0
votes

I have the following dataframe:

Index    PC1             PC2        Accession_no
1    0.037971642    -0.025406954    TKNK_MOUSE
2   -0.046295802    -0.026290312    TKN1_MOUSE
3   -0.113487427     0.06782228     GALA_MOUSE
4   -0.014441264    -0.116523664    VGF_MOUSE
5   -0.112657991    -0.089605827    CALCA_MOUSE

I want to plot PC1 vs PC2 and label points with index say 1,2 and 4 with the accession_no (also change the color of the dots).

I have the following code that plots and also colors the points accordingly.

plot(df$PC1,df$PC2, pch=19, col=ifelse(rownames(df)==c("1","2","4"),"red","black"))

However, only the first two points are showing in different color. Moreover, I also want to label the exact same points with their corresponding Accession_no

1
Have you tried to replace rownames(df)==c("1","2","4") by rownames(df) %in% c("1","2","4") ? - fmarm
yes, it works. How do I get the labels for these points? - kdba

1 Answers

0
votes
select <- c(1,2,4)
plot(df$PC1,df$PC2, pch=19, col=ifelse(rownames(df) %in% select,"red","black"))
text(df$PC1[select],df$PC2[select]+0.01,labels=df$Accession_no[select],cex=0.6)

This does the job here.