Entering edit mode
7.5 years ago
SheelS
▴
40
I have built up a Genomic Relationship Martrix based on my SNP dataset.
And I want to assess the population structure using PCA. The R package I used is called prcomp
.
Now I have made a PCA plot looks like link below, but all dots are with black dots.
https://postimg.org/image/46xmv63oh/
I wonder how can I make them as different colors based on the 'GROUP' column in my example dataset.
Can anyone show me how to make it looks good step by step based on my GRM and SAMPLE file?
# Example dataset. 5 samples.
GRM <- read.table(textConnection("
1.63650789764753 0.340509314443612 0.226099930201148 0.376620916053879 0.158254769681645
0.340509314443612 1.83400749362486 0.717660112084021 0.92036913092054 0.765351049567537
0.226099930201148 0.717660112084021 1.76647251391584 0.589245058579147 0.735155682954209
0.376620916053879 0.92036913092054 0.589245058579147 1.74051192016634 0.56761339005198
0.158254769681645 0.765351049567537 0.735155682954209 0.56761339005198 1.66126870690556
"), header = F)
SAMPLE <- read.table(textConnection("
ID GROUP
1 A
2 A
3 B
4 C
5 D
"), header = F)
This is an R programming question, you should probably be searching/asking on StackOverflow.
You don't show how you plot so it's not easy to help you because there are different ways of specifying colors depending on the graphics system you're using. If using the base R plot() function then have a look at the col option.