2016-04-30 76 views
0

我正在使用ggplot做繪圖集羣。我想爲羣集0定製顏色,但不知何故,它不起作用。手動着色點geom_point

Hasil<-Result$cluster 
latitude<-datafile$latitude 
longitude<-datafile$longitude 
stdb<-data.frame(latitude,longitude,Hasil) 

plotpeta<- function(stdb){ 
#read shape file 
map<- readOGR(dsn="D:/peta", layer="indo_districts") 
[email protected]$id <- rownames([email protected]) 

#convert to dataframe 
maps<-fortify(map) 
mergemap <- join(maps, [email protected], by="id") 
ggplot(mergemap) + aes(long,lat, group=group) + 
    geom_polygon(data=map, aes(long, lat, group=group), color="grey") + 
    geom_path(data=map, color="white")+ 
    geom_polygon(data=mergemap, aes(long,lat))+ 
    theme(legend.position = "bottom") + 
    geom_point(data=stdb, aes(longitude,latitude,group=1), color="white", size=2) + 
    geom_point(data=stdb, aes(longitude,latitude, group=1, color=factor(Hasil)), size=2) + 
    ylab("Longitude") + xlab("Latitude") + 
    scale_color_hue(name="Hasil", l=40, c=40) + 
    guides(col=guide_legend(ncol=10, byrow = TRUE, override.aes =list(size=3))) + 
    guides(fill=guide_legend(ncol=10, byrow=TRUE), size=1)+ 
    coord_equal() 

} 

使集羣繪製原來這樣

the cluster 0 in the picture has color that is similar to cluster 1,2

我想不同的集羣0,因爲它的噪音。 任何有關如何使它變白的建議? 謝謝:)

回答

0

如果設置通過創建級聯列表中手動調色板:

您可能需要使用scale_color_manual當你看到合適的應用顏色。

您可以使用values=參數將顏色指定到分類變量的適當級別,或者如果您有特定的離散數字或系列的名稱,則使用數字。

scale_colour_manual(values = c("0" = "white","1" = "blue","7" = "orange")) + 

確保這一行代碼直接跟在描述數據點的geom_point之後。

如果你想保持一堆等於「藍,只是定義的值列表中的連續清單所有這些值:

previous color.., c("1", "2", "3", "4") = "blue" , ...other colors 

,如果你是明確的,佔了所有可能的結果和用語法這個應該是一絲不苟的。