I followed the post related to [PCA from vcf file][1]
 followed by 

    library("SNPRelate")
    vcf.fn<-"~/xxx/tmp.vcf"
    snpgdsVCF2GDS(vcf.fn, "ccm.gds",  method="biallelic.only")
    genofile <- openfn.gds("ccm.gds") 
    ccm_pca<-snpgdsPCA(genofile)
    plot(ccm_pca$eigenvect[,1],ccm_pca$eigenvect[,2] ,col=as.numeric(substr(ccm_pca$sample, 1,3) == 'CCM')+3, pch=2)

  [1]: https://www.biostars.org/p/44735/#423942

I got a plot but not able to conclude from it. There is no legend or color code differentiation between the breeds. My understanding to R is very limited and couldn't able to find a fix. May I get some help/tips to fix this problem.
I will be grateful to you all.

I am confident that you know to what these numbers relate?

# set specific colours for each factor level

You can set colours manually to any vector like this:

    x <- c('01','03','05','01','08','08','01','03','05')
    unique(x)
    [1] "01" "03" "05" "08"
    colours <- c('royalblue', 'forestgreen', 'red4', 'pink')[factor(x, levels = c('01', '03', '05', '08'))]

Here, the order of the colours (`'royalblue', 'forestgreen', 'red4', 'pink'`) must match the order of the factor levels that you are setting (`'01', '03', '05', '08'`).


# apply a colour gradient / pre-built palette to your factor levels
You can also automatically assign colours via *RColorBrewer*:

    require('RColorBrewer')
    pick.col <- brewer.pal(10, 'Spectral')
    colII <- colorRampPalette(pick.col)(length(unique(x)))[factor(x, levels = c('01', '03', '05', '08'))]

Here, I use the '*Spectral*' palette. For other palettes, take a look here (half-way): http://www.sthda.com/english/wiki/colors-in-r

<a href="https://ibb.co/Vmjvygx"><img src="https://i.ibb.co/sHmFSKC/colors-in-r-rcolorbrewer-palettes.png" alt="colors-in-r-rcolorbrewer-palettes" border="0"></a>

# create your own palette

For a custom palette, do something like this:

    myPalette <- c('white','pink','red2','red4')
    colorRampPalette(myPalette)(length(unique(x)))[factor(x, levels = c('01', '03', '05', '08'))]

----------------------
---------


You can then plot a custom legend via the `legend()` function, which comes with base R.

Kevin
