我需要一些帮助来修改我的 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))
非常感谢您的帮助。