2015-05-06 40 views
0

我正在使用ggbiplot()並希望操作數據點的顏色和形狀,以使它們更易於打印。目前,我從ggbiplot()獲得了默認的彩虹。我嘗試過使用參數「+ scale_colour_discrete」和「+ scale_shape_manual」,但「groups =」參數ggbiplot似乎覆蓋了這些參數。如果我消除「groups =」參數,則不能繪製橢圓。 「+主題」的論點工作得很好。我的代碼如下。我知道我可以在常規biplot()函數中更容易地操縱顏色/形狀,但我喜歡ggbiplot()提供的置信區間橢圓。在ggbiplot中更改點顏色和形狀

g <- ggbiplot(size.pca, choices=1:2, obs.scale = 1, var.scale = 1, 
     groups=fieldnames, ellipse = TRUE,ellipse.prob=0.68, varname.size=4) 

g <- g + scale_colour_discrete(name=" ") #only the name=" " part of this seems to work. 

g <- g + scale_shape_manual(values=c(17,16,16,16,16,16), name= " ") #trying to indicate one population different from the rest, but it doesn't seem to do anything (no error either, just no change in the output). 

g <- g + theme_bw() +theme(legend.direction = 'horizontal', 
     legend.position = 'top') 

print(g) 
+3

如果您提供了一些樣本輸入數據,那麼我們就可以看到您的情節,並測試可能的解決方案。在[如何創建可重現的示例]中查看包含數據的提示(http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick

+0

查看此答案:http: //stackoverflow.com/a/40305464/4477364 – Joe

回答

0

一個geom_point()參數添加到您的ggplot腳本和scale_color_manual覆蓋組的默認顏色不改變分組載體是這樣的:

g <- ggbiplot(size.pca, choices=1:2, obs.scale = 1, var.scale = 1, 
     groups=fieldnames, ellipse = TRUE,ellipse.prob=0.68, varname.size=4) + 
geom_point(aes(colour = fieldnames), size = "your size") + 

scale_color_manual(values=c(17,16,16,16,16,16)) + 

theme_bw() +theme(legend.direction = 'horizontal', 
     legend.position = 'top') 

print(g) 

這應該工作!