我正在使用 eulerr 包 来制作维恩图/欧拉图。但是,我想将这些图添加到面板图中,但我不知道如何添加。每次我制作欧拉图时,它都会创建一个新图形,而不是添加到面板中。
它一定在内部某个地方调用一个新的图形窗口?在 documentation 中,我看到内部函数
plot.eulergram
有一个 newpage = TRUE
默认参数,但是当我尝试使用函数 plot.eulergram()
而不是仅仅 plot()
时,它说该函数不存在。
这是一个简单的例子,我尝试使用mfrow,layout和fig:
library(eulerr)
x <- data.table("A" = rep(c(TRUE,FALSE), times = 20),
"B" = rep(c(TRUE,FALSE), each = 10),
"C" = rep(c(TRUE,TRUE,FALSE,TRUE), times = 5))
fit.ellipses <- eulerr::euler(combinations = x, shape = "ellipse")
# here is the basic plot, this part works
plot(fit.ellipses)
# try with mfrow, doesn't work
par(mfrow = c(1,2))
plot(fit.ellipses)
plot(fit.ellipses)
# try with layout, doesn't work
m <- matrix(1:2, ncol = 2)
layout(mat = m)
plot(fit.ellipses)
plot(fit.ellipses)
# try with fig, doesn't work
par(fig = c(0,.5,0,1))
plot(fit.ellipses)
par(fig = c(.5,1,0,1), new = TRUE)
plot(fit.ellipses)
# try that internal function, isn't there??
plot.eulergram(fit.eliipses, newpage = F)
# Error in plot.eulergram(fit.eliipses, newpage = F) :
# could not find function "plot.eulergram"
从文档来看,它看起来可能使用网格图形系统而不是基本 R,所以也许这就是这些面板功能不起作用的原因,但我不明白这到底意味着什么。谢谢您的建议!
您正在寻找
gridExtra
套餐。 grid.arrange()
可能就是您所需要的:
library(eulerr)
library(data.table)
library(gridExtra) # for arranging the plots
x <- data.table("A" = rep(c(TRUE,FALSE), times = 20),
"B" = rep(c(TRUE,FALSE), each = 10),
"C" = rep(c(TRUE,TRUE,FALSE,TRUE), times = 5))
fit.ellipses <- eulerr::euler(combinations = x, shape = "ellipse")
# here is the basic plot, this part works
plot(fit.ellipses)
# Using grid.arrange() from gridExtra:
grid.arrange(
plot(fit.ellipses),
plot(fit.ellipses)
)
# you can also use ncol/nrow to define the plot layout
grid.arrange(
plot(fit.ellipses),
plot(fit.ellipses),
plot(fit.ellipses),
nrow=1
)