有人知道如何更改磅值并仍然在下面的代码中保持组颜色吗?
只需添加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)
答案 0 :(得分: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')
答案 1 :(得分: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')