ggbiplot - 更改组颜色和标记

时间:2016-10-27 14:58:16

标签: r pca ggbiplot

在示例ggbiplot脚本图中有3组,如何更改标记颜色和形状?

library(ggbiplot)
data(wine)
wine.pca <- prcomp(wine, scale. = TRUE)
ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, group=wine.class,
         varname.size = 3, labels.size=3, 
         ellipse = TRUE, circle = TRUE) +
  scale_color_discrete(name = '') +  
  geom_point(aes(colour=wine.class), size = 3) +
  theme(legend.direction ='horizontal', 
        legend.position = 'top')

1 个答案:

答案 0 :(得分:7)

以下适用于我。

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

enter image description here

对于图例,诀窍似乎是对namescale_color_manual使用相同的scale_shape_manual