繁体   English   中英

如何自动为多个组添加/分配颜色

[英]How to add/assign color to many groups automatically

我需要一些帮助来修改我的 R 脚本,该脚本可以为每个组分配不同的颜色。 我总是需要手动指定颜色名称/代码 [例如,scale_fill_manual(values = c("grey", "red", "yellow", "green"))]。

完整的 R 脚本在这里

     library(ggbiplot)
iris<- read.csv("data_umar.csv")
log.ir <- iris[, 1:11]
ir.species <- iris[, 12]

ir.pca <- prcomp(log.ir, center = TRUE, scale. = TRUE)

##for PC3 and PC4 choices = c(1,2)

ggbiplot(ir.pca, choices = c(1,2), obs.scale = 1, var.scale = 1, groups = ir.species, alpha = 0) +
  theme(legend.direction = 'vertical', legend.position = 'right') + 
  scale_color_manual(values=c("Black", "Black", "Black", "Black")) +
  scale_fill_manual(values = c("grey", "red", "yellow", "green")) + # just offset by one to show
  geom_point(size = 1.2, shape = 21, aes(fill = groups, color = groups))

非常感谢您的帮助。

scale_color_manual(值=ir.species)

scale_color_manual(values=1:20) # 假设有 20 种颜色

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM