2017-05-11 56 views
2

我有一个具有特定列和行组的数据矩阵。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 

这里上校的名称是“促销员”,“外显子” ......和组是“无”,“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

马山德里解决方案:

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

enter image description here

+0

自动绘制的第一个参数应该是p rcomp对象,而不是旋转;尝试'autoplot(prcomp(df [,1:17],scale = TRUE),color ='groups')' – scoa

回答

1

以下选项中autoplot可供prcomp对象:

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

感谢这工作。是否有可能就df的第一栏看看分销基地唐集团。例如,我希望看到发起人在小组之间分配。 – user44552

+0

'prcomp(df [,1],scale = TRUE)'表示您正试图在单个变量上生成PCA。这个不成立。 –

+0

是的。我想看看Promoters与另一个col的区别。值。我通过在df上进行子集化来做到这一点。谢谢。 – user44552