0

I need some help to modify my R script that could assign different color to each group. I always need to specify color name/code manually [e.g., scale_fill_manual(values = c("grey", "red", "yellow", "green"))].

Complete R script is here

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

Many thanks for the help.

karadeniz
  • 5
  • 2
  • Can you try and make this code reproducible by either including a large enough sample of your data, or using a standard dataset or generating a dummy dataset with the same structure as your own data? Also, if the issue is with the colour scales; do you need the ggbiplot to show the problem? – teunbrand Apr 17 '21 at 19:53
  • @teunbrand thanks for the comments. Can I share the data file with following sharing link https://drive.google.com/file/d/1gw9SDbAhRFK9QU5Yd30v8DlPH95tRWbY/view?usp=sharing Please kindly get the data from this link. Many thanks – karadeniz Apr 17 '21 at 20:06
  • @teunbrand I also revised my R script for the shared CSV file – karadeniz Apr 17 '21 at 20:07
  • I can't get ggbiplot to install, so I apologise that I can't be of more help. – teunbrand Apr 17 '21 at 20:20
  • @teunbrand no problem. You may get it with library(devtools) install_github("vqv/ggbiplot", force = TRUE) – karadeniz Apr 17 '21 at 20:30

1 Answers1

0

scale_color_manual(values=ir.species)

scale_color_manual(values=1:20) # assumes 20 colours

CALUM Polwart
  • 497
  • 3
  • 5