首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改r中ggbiplot中的点颜色和形状

更改r中ggbiplot中的点颜色和形状
EN

Stack Overflow用户
提问于 2015-05-07 06:20:14
回答 1查看 2.1K关注 0票数 0

我正在使用ggbiplot(),并希望操作数据点的颜色和形状,使它们对打印机更友好。目前我从ggbiplot()中得到了默认的彩虹颜色。我尝试过使用参数"+ scale_colour_discrete“和"+ scale_shape_manual”,但是"groups=“参数ggbiplot似乎覆盖了它们。如果我去掉"groups=“参数,那么椭圆就不能被画出来。"+主题“参数可以很好地工作。我的代码如下。我知道在常规的biplot()函数中可以更容易地操作颜色/形状,但我喜欢ggbiplot()提供的置信区间椭圆。

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2015-10-31 21:09:26

向您的ggplot脚本和scale_color_manual添加一个geom_point()参数,以覆盖组的默认颜色,而不会像下面这样更改分组向量:

代码语言:javascript
复制
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)

这应该行得通!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30088686

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档