2014-06-07 76 views
3

有人有一個想法如何改變點的大小,並仍然保持在下面的代碼中的組顏色?ggbiplot - 改變點的大小

只需添加geom_point(size = 8)即可將所有點的顏色更改爲黑色。

代碼:

library(ggbiplot) 
data(wine) 
wine.pca <- prcomp(wine, scale. = TRUE) 
g <- ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, 
       groups = wine.class, varname.size = 8, labels.size=10 , ellipse = TRUE, circle = TRUE) 
g <- g + scale_color_discrete(name = '') #+ geom_point(size = 8) 
g <- g + opts(legend.direction = 'horizontal', 
       legend.position = 'top') 
print(g) 

回答

6

添加色彩審美內geom_point將繼續按組彩色的點。另外,我將opts更改爲theme,因爲opts已被棄用。

ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, group=wine.class, 
       varname.size = 8, labels.size=10, 
       ellipse = TRUE, circle = TRUE) + 
    scale_color_discrete(name = '') + 
    geom_point(aes(colour=wine.class), size = 8) + 
    theme(legend.direction ='horizontal', 
     legend.position = 'top') 
+0

非常感謝的快速響應和幫助 – lroca

0

我碰到這個問題的同時,試圖讓我的積分更小。 eipi10的答案很好地解決了這個問題,通過簡單地繪製默認點來製作點。雖然這是一個簡單的解決方案,它的工作原理,我可以提出以下建議,這使得默認的點不可見通過設置alpha=0並在上述geom_point線中繪製點:

ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, group=wine.class, 
    varname.size = 8, labels.size=10, 
    ellipse = TRUE, circle = TRUE, 
    alpha=0 #here's the change 
) + 
scale_color_discrete(name = '') + 
geom_point(aes(colour=wine.class), size = 0.5) + #set size of smaller points here 
theme(legend.direction ='horizontal', 
    legend.position = 'top')