在r中改变ggbiplot中的点颜色和形状 [英] change point colors and shapes in ggbiplot in r
问题描述
我使用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)
$ bg < - g + scale_colour_discrete(name =)#只是名称=这部分似乎工作。
g < - g + scale_shape_manual(values = c(17,16,16,16,16,16),name =)#trying表示一个与其他人不同的人群,但它似乎没有做任何事情(也没有错误,只是没有改变输出)。
g < - g + theme_bw()+ theme(legend.direction ='horizontal',
legend.position ='top')
print(g )
添加 geom_point( )
参数到您的ggplot脚本和 scale_color_manual
来覆盖组默认颜色,而无需像这样更改分组向量:
g < - ggbiplot(size.pca,choices = 1:2,obs.scale = 1,var.scale = 1,
组= fieldnames,ellipse = TRUE,ellipse.prob = 0.68,varname.size = 4)+
geom_point(aes(color = fieldnames),size =your size)+
scale_color_manual (values = c(17,16,16,16,16,16))+
theme_bw()+ theme(legend.direction ='horizontal',
legend.position =' (')
$ b print(g)
这应该可行! p>
I am using ggbiplot() and would like to manipulate the colors and shapes of the datapoints to make them more printer friendly. Currently I get the default rainbow of colors from ggbiplot(). I have tried using the arguments "+ scale_colour_discrete" and "+ scale_shape_manual" but the "groups=" argument ggbiplot seems to override these. If I eliminate the "groups=" argument then ellipses can't be drawn. The "+ theme" argument works just fine. My code is below. I know I could manipulate the colors/shapes more easily in the regular biplot() function, but I like the confidence interval ellipses provided by 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)
add a geom_point()
argument to your ggplot script and the scale_color_manual
to override the group default colour without changing the grouping vector like this:
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)
This should work!
这篇关于在r中改变ggbiplot中的点颜色和形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!