3

我正在使用 VennDiagram 包制作维恩图。他们出来了:

library(VennDiagram)
library(cowplot)


png("p.png")
p = draw.pairwise.venn(30,20,11, category = c("Dogs", "Cats"), lty = rep("blank", 2), fill = c("light blue", "pink"), alpha = rep(0.5, 2), cat.pos = c(-45, 45), cat.dist = rep(0.025, 2))
dev.off()

png("q.png")
draw.pairwise.venn(15, 20, 10, category = c("Rats", "Mice"), lty = rep("blank", 2), fill = c("light blue", "pink"), alpha = rep(0.5, 2), cat.pos = c(-45, 45), cat.dist = rep(0.025, 2))
dev.off()    

在此处输入图像描述 在此处输入图像描述

但是,如果我尝试使用 cowplot 的 plot_grid() 将它们并排绘制,就会发生不好的事情:

p = draw.pairwise.venn(30,20,11, category = c("Dogs", "Cats"), lty = rep("blank", 2), fill = c("light blue", "pink"), alpha = rep(0.5, 2), cat.pos = c(-45, 45), cat.dist = rep(0.025, 2))

q = draw.pairwise.venn(15, 20, 10, category = c("Rats", "Mice"), lty = rep("blank", 2), fill = c("light blue", "pink"), alpha = rep(0.5, 2), cat.pos = c(-45, 45), cat.dist = rep(0.025, 2))

png('pq.png')
plot_grid(p, q, labels = "AUTO")
dev.off()

Error: Argument needs to be of class "ggplot", "gtable", "grob", "recordedplot", or a function that plots to an R graphicsdevice when called, but is a gList
Calls: plot_grid -> align_plots -> lapply -> FUN -> plot_to_gtable
Execution halted

draw.pairwise.venn()没有使对象与plot_grid().

class(p)
[1] "gList"

所以我想我需要将 gList 变成 ggplot 对象或其他兼容的东西,即使它gList被列为合适的类型。我找不到任何东西。我想使用cowplot,因为它能够很好地标记要发布的子图。

4

1 回答 1

3

将这些情节包装成grobTree()我的作品。我认为 VennDiagram 包应该归咎于此。它不应该返回 a gList,它应该将 a 包装gList成一个 grob。无论如何,这可以在cowplot中修复。随时在这里提出问题。

library(VennDiagram)
#> Loading required package: grid
#> Loading required package: futile.logger
library(cowplot)
library(grid)

p = draw.pairwise.venn(30,20,11, category = c("Dogs", "Cats"), lty = rep("blank", 2), fill = c("light blue", "pink"), alpha = rep(0.5, 2), cat.pos = c(-45, 45), cat.dist = rep(0.025, 2))

q = draw.pairwise.venn(15, 20, 10, category = c("Rats", "Mice"), lty = rep("blank", 2), fill = c("light blue", "pink"), alpha = rep(0.5, 2), cat.pos = c(-45, 45), cat.dist = rep(0.025, 2))

plot_grid(grobTree(p), grobTree(q), labels = "AUTO")

reprex 包(v0.2.0)于 2018 年 6 月 23 日创建。

于 2018-06-24T01:19:26.103 回答