R中的组的PCA或MDS

时间:2017-05-11 14:17:46

标签: r pca mds

我有一个具有特定列和行组的数据矩阵。

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

这里的Col名称是“Promoters”,“Exons”......和Groups是“none”,“RTK”等。

我需要做一些PCA,例如看看发起人如何在众多群体中分发。我一直在尝试使用ggfortify和其他R包,但无法得到清晰的图片。非常感谢任何帮助。

这是我得到的错误:

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

Error: Objects of type numeric not supported by autoplot.

使用:

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

该组没有颜色,也没有任何消息。

enter image description here

Marco Sandri解决方案:

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

enter image description here

1 个答案:

答案 0 :(得分:1)

autoplotprcomp个对象提供了以下选项:

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