Entering edit mode
2.9 years ago
mohammedtoufiq91
▴
260
Hi,
I am making PCA plot in R using PCAtools
for different group of individuals. The are 65 groups in the sample metadata. At the moment, for smaller groups I simply specify color for each of them in colkey
(for instance, "Group 1" = "#004181"
, "Group 2" = "#0077BA"
, ................, etc). I am not sure how to add colors for more number of groups and manually specifying them would be tedious. Is there a better way to do this?
Plot_Type = "PCA2D"
pdf(paste0(Plot_Type,"_PC1_vs_PC2.pdf"),height = 7,width = 10)
biplot(p,
x = 'PC1', y = 'PC2',
lab = NULL,
colby = 'Group', colkey = c('Group 1' = '#004181', 'Group 2' = '#0077BA', 'Group 3' = '#4E564D', 'Group 4' = '#6BA3D7', 'Group 5' = '#8B63FF'),
legendPosition = 'right', legendLabSize = 13, legendIconSize = 3.0,
subtitle = 'PC1 vs. PC2')
dev.off()
I will appreciate any help. Thank you!
Best Regards,
Toufiq
@zx8754
Thank you very much for the prompt response and additional reference link. True, 65 is difficult to distinguish, but perhaps, would likely assist if there are lower numbers of groups going forward. I like
randomcoloR
library for further analysis. How to generate a number of most distinctive colors in RApart from being labelled as
Group 1
,Group 2
, there are other groups like3B
,3C
,3ZX
,7DG
,90CC
,HC
,Cont1
,.... Meaning 65 groups are non-uniformly labelled.replace
paste("Group", 1:n)
with a character vector containing group names.cpad0112,
thank you very much. This works.