change point colors and shapes in ggbiplot in r

大憨熊 提交于 2019-12-25 03:43:13

问题


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)

回答1:


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!



来源:https://stackoverflow.com/questions/30088686/change-point-colors-and-shapes-in-ggbiplot-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!