我创建了一个热图和一个PCA图,并试图将它们合并为一个图。但是它们没有显示为一个图。
library(factoextra)
library(FactoMineR)
library(pheatmap)
library(RColorBrewer)
library(ggpubr)
# make test matrix
test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")
# define the annotation
annotation_row = data.frame(GeneClass = factor(rep(c("Path1", "Path2", "Path3"), c(10, 4, 6))),
AdditionalAnnotation = c(rep("random1", 10), rep("random2", 10)))
rownames(annotation_row) = paste("Gene", 1:20, sep = "")
a=pheatmap(test, annotation_row = annotation_row)
# creating pca
# Compute PCA with ncp = 3
res.pca <- PCA(test, ncp = 3, graph = FALSE)
# Compute hierarchical clustering on principal components
res.hcpc <- HCPC(res.pca, graph = FALSE)
# Principal components + tree
b=plot(res.hcpc, choice = "3D.map")
#arranging in a single plot
ggarrange(a$gtable, b, labels = c("A", "B"))
输出无pca:
1条答案
按热度按时间t3irkdon1#
plot
(或plot.HCPC
)返回NULL
,因此b
为NULL
。从
?ggarrange
开始,它期望一个图表列表被安排到网格中,图表可以是ggplot2
图表对象,也可以是任意的gtable。因此,一个选项是使用
{ggplotify}
包中的as.ggplot()
函数将基础图转换为ggplot对象,然后将其传递给ggarrange
。