根据colnames绘制PCA3D图?

时间:2018-06-11 09:29:55

标签: r ggplot2 pca bioconductor scatter3d

我有一个像打击一样的表:我可以根据下面的推荐绘制2维的简单PCA图,但我想基于col-names得到3D PCA?

                   4_rep1 4_rep2     8_rep1     8_rep2     7_rep1     7_rep2   3_rep1   3_rep2 

ENSG00000000003    2202    1787       2357       2257        945        977    1362      8536
ENSG00000000005      33      15         13         12         21         37      20      15          
ENSG00000000419     557     442        696        679        359        398     279     314        
ENSG00000000457     343     251        218        215        212        219     221     254         
ENSG00000000460     276     242        189        202        123        126     206     218         

plotPCA(newSeqExpressionSet(as.matrix(data),col=colors))

提前感谢您的任何建议!

1 个答案:

答案 0 :(得分:3)


假设你需要一个散点3d图,其中特征向量作为轴,变量的权重作为坐标,你可以找到几个选项:

# here the data
results <-    data.frame(matrix(c(2202,33,557,1787,15,442,2357,13,696,2257,12,679),nrow=3,ncol=4))
colnames(results) <- c("4_rep1","4_rep2","8_rep1","8_rep2")
rownames(results) <- c("ENSG00000000003","ENSG00000000005","ENSG00000000419")

# then a small transformation
library(data.table)
t_results <- transpose(results)
colnames(t_results) <- rownames(results)
rownames(t_results) <- colnames(results)

#lastly the plot
library(scatterplot3d) 
scatterplot3d(t_results[,1],t_results[,2],t_results[,3], main="Very    simple")

enter image description here

更酷一点:

library(rgl)
plot3d(results[,1]  ,results[,2],results[,3], col="red", size=3)

enter image description here

这一个:

    p <- plot_ly(t_results, x = ~ENSG00000000003, y = ~ENSG00000000005, z = ~ENSG00000000419) %>%
  add_markers() %>%
  layout(scene = list(xaxis = list(title = 'ENSG00000000003'),
                      yaxis = list(title = 'ENSG00000000005'),
                      zaxis = list(title = 'ENSG00000000419')))

    p

enter image description here