我有一个像打击一样的表:我可以根据下面的推荐绘制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))
提前感谢您的任何建议!
答案 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")
更酷一点:
library(rgl)
plot3d(results[,1] ,results[,2],results[,3], col="red", size=3)
这一个:
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