R语言 e1 + e2 + plot_layout(ncol = 1)中出现错误:二元运算符的非数值参数

cyej8jka  于 2022-12-06  发布在  其他
关注(0)|答案(1)|浏览(155)

我使用以下软件包来合并plots库(ggplot2)库(patchwork)
当尝试合并绘图时使用

(f5 | f2 | f3 | f4) / f1$gtable

它会将输出建立为:

但是当我用

f1$gtable / (f5 | f2 | f3 | f4)

它会抛出如下错误:

Error in e1 + e2 + plot_layout(ncol = 1): non-numeric argument to binary operator
Traceback:

1. `/.ggplot`(f1$gtable, (f5 | f2 | f3 | f4))

我尝试了(f1$gtable) / (f5 | f2 | f3 | f4)之类的所有组合,但仍然抛出相同的错误
可再现数据:

#crate 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 = "")
#Plot 1
f1=pheatmap(test)

#Creating group
group_df = data.frame(Groups=rep(c("Group1", "Group2"), c(5,5)))

#Plot 2
int = c("Gene1", "Gene2","Gene3")
df1=t(test[rownames(test) %in% int,])
df1 = as.data.frame(df1)
df1$Mean = rowMeans(df1[,])
df1 = cbind(group_df, df1)
f2=ggboxplot(df1, x = "Groups", y = "Mean", color = "Groups")

#Plot 3
int = c("Gene4", "Gene5","Gene6")
df1=t(test[rownames(test) %in% int,])
df1 = as.data.frame(df1)
df1$Mean = rowMeans(df1[,])
df1 = cbind(group_df, df1)
f3=ggboxplot(df1, x = "Groups", y = "Mean", color = "Groups")

#Plot 4
int = c("Gene7", "Gene8","Gene9")
df1=t(test[rownames(test) %in% int,])
df1 = as.data.frame(df1)
df1$Mean = rowMeans(df1[,])
df1 = cbind(group_df, df1)
f4=ggboxplot(df1, x = "Groups", y = "Mean", color = "Groups")

#Plot 5
int = c("Gene10", "Gene5","Gene1")
df1=t(test[rownames(test) %in% int,])
df1 = as.data.frame(df1)
df1$Mean = rowMeans(df1[,])
df1 = cbind(group_df, df1)
f5=ggboxplot(df1, x = "Groups", y = "Mean", color = "Groups")
e4eetjau

e4eetjau1#

看起来ggplotify可以将gtable转换为ggplot

ggplotify::as.ggplot(f1$gtable) / (f5 | f2 | f3 | f4)

使用来自this questionanswer的想法

相关问题