ggbiplot - change the point size

不打扰是莪最后的温柔 提交于 2019-12-07 12:21:01

问题


Does someone have an idea how to change the point size and still maintain the group colors in the code below?

Just adding the geom_point(size = 8) changes the colors of all the points to black.

Code:

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)

回答1:


Adding a color aesthetic inside geom_point will keep the points colored by group. Also, I changed opts to theme, since opts has been deprecated.

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')



回答2:


I came across this question while trying to make my points smaller. The answer by eipi10 does solve this problem nicely for making the points larger by simply plotting over the default points. While this is a simple solution that works, may I propose the following, which makes the default points invisible by setting the alpha=0 and plotting the points in the aforementioned geom_point line:

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')


来源:https://stackoverflow.com/questions/24101287/ggbiplot-change-the-point-size

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