0

我正在使用 ggbiplot() 并希望操纵数据点的颜色和形状以使它们对打印机更友好。目前我从 ggbiplot() 获得了默认的彩虹色。我曾尝试使用参数“+ scale_colour_discrete”和“+ scale_shape_manual”,但“groups=”参数 ggbiplot 似乎覆盖了这些。如果我消除“groups=”参数,则无法绘制椭圆。“+ 主题”参数工作得很好。我的代码如下。我知道我可以在常规 biplot() 函数中更轻松地操纵颜色/形状,但我喜欢 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)
4

1 回答 1

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)

这应该工作!

于 2015-10-31T13:09:26.367 回答