ggbiplot - change the point size

7.2k Views Asked by At

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

There are 2 best solutions below

2
On BEST ANSWER

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

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