如何add/assign自动给多个组着色

How to add/assign color to many groups automatically

我需要一些帮助来修改可以为每个组分配不同颜色的 R 脚本。我总是需要手动指定颜色 name/code [例如 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 种颜色