ggbiplot-更改组的颜色和标记 [英] ggbiplot - change the group color and marker

查看:492
本文介绍了ggbiplot-更改组的颜色和标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

以下内容对我有用.

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

对于图例,窍门似乎是对scale_color_manualscale_shape_manual使用相同的name.

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

这篇关于ggbiplot-更改组的颜色和标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆