簡體   English   中英

plot單排plot不顯示?

[英]The plot does not display when arranged as single plot?

我創建了一個熱圖和一個 pca plot 並試圖將它們合並為一個圖形。 但是沒有顯示為單個數字。

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"))

output 沒有 pca: 在此處輸入圖像描述

plot (或plot.HCPC )返回NULL ,因此bNULL

?ggarrange ,它希望將一系列繪圖排列到網格中。 這些圖可以是ggplot2 plot 對象或任意 gtables。

因此,一種選擇是使用來自{ggplotify} package 的as.ggplot() function 將該基數 plot 轉換為 ggplot object,然后將其傳遞給ggarrange

b <- ggplotify::as.ggplot(~plot(res.hcpc, choice = "3D.map"))

#arranging in a single plot
ggarrange(a$gtable, b, labels = c("A", "B"))

安排的地塊


暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM