ggbiplot - change the group color and marker

后端 未结 1 1316
攒了一身酷
攒了一身酷 2021-01-03 01:09

In the example ggbiplot script plot there are 3 groups, how can I change the marker colors and shapes?

library(ggbiplot)
data(wine)
wine.pca <- prcomp(win         


        
相关标签:
1条回答
  • 2021-01-03 02:00

    The following works for me.

    ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, group=wine.class,
         varname.size = 3, labels.size=3, ellipse = TRUE, circle = TRUE) +
    scale_color_manual(name="Variety", values=c("orange", "purple", "green")) +  
    scale_shape_manual(name="Variety", values=c(17:19)) +
    geom_point(aes(colour=wine.class, shape=wine.class), size = 3) +
    theme(legend.direction ="horizontal", 
          legend.position = "top")
    

    For the legend, the trick seems to be to use the same name for scale_color_manual and scale_shape_manual.

    0 讨论(0)
提交回复
热议问题