Search code examples
rpcamds

PCA or MDS for groups in R


I have a data matrix which has specific columns and row-groups.

Promoters Exons Introns Intergenic  UTR5  UTR3 EncodeDnase   TFBS CpGislands CpGshores CpGshelf Enhancer Valley umrs canyons genebodies enhancer34 groups
44905 34778   49182      32420 21190  6537       75693  61543      54879     13759     3666   103839    544    8    9148      63403       7366   none
78256 63745   91197      57814 34416 13868      148583 130801     105784     28060     6529   189413   1714    5   18539     116294       8381    RTK
143570 98141  138767      71540 67754 16907      229364 217258     173782     40134     7885   269992   2284   26   29641     176748      17150    IDH
45056 37201   58839      38119 21086  8157       86207  70401      55729     18749     4970   120537    960   14   10717      72760       5439   none
107204 75309  107776      65783 48986 12059      179100 163906     138259     30409     5969   220463   1951   30   23413     136981      13742  CEBPA
106545 75721  109299      67453 47773 13183      180403 163493     134882     32027     6524   224426   1933   25   23011     138924      13242  CEBPA

Here Col Names are "Promoters", "Exons"... and Groups are "none", "RTK" etc..

I need to do some PCA to see for example how Promoters distribute amongst the many groups. I have been trying to do using ggfortify and other R packages but unable to get a clear picture. Any help is much appreciated.

This is the error I get:

> autoplot(prcomp(df[,1:17], scale=TRUE)$rotation[,1], color='groups')

Error: Objects of type numeric not supported by autoplot.

For Using:

autoplot(prcomp(df[,1:17], scale=TRUE), color='groups')

The group does not have the colors nor do i get any message.

enter image description here

Marco Sandri Solution:

library(ggfortify)
autoplot(prcomp(df[,1:17], scale=TRUE), loadings = TRUE, loadings.label = TRUE,
         data = df, colour = 'groups')

enter image description here


Solution

  • The following options are available in autoplot for prcomp objects:

    library(ggfortify)
    autoplot(prcomp(df[,1:17], scale=TRUE), loadings = TRUE, loadings.label = TRUE,
             data = df, colour = 'groups')