3

有人知道如何更改点大小并仍然保持下面代码中的组颜色吗?

只需添加将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)
4

2 回答 2

7

在内部添加颜色美学geom_point将保持按组着色的点。另外,我更改optstheme, 因为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')
于 2014-06-07T23:38:00.050 回答
1

我在试图缩小我的观点时遇到了这个问题。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')
于 2017-04-29T15:37:08.847 回答