在 PDF 中减少元分析子图之间的 space
Reduce space between meta-analysis sub-plots in a PDF
我正在创建一个包含 3 个部分的图形,这些部分是使用 metafor
包创建的森林图。我怎样才能减少子图之间的白色 space 使它们靠得更近?
这里是示例数据和代码
library(metafor)
dat <- read.csv(("https://raw.githubusercontent.com/aelhak/data/main/dat2.csv"))
graphics.off()
grDevices::cairo_pdf("plot.pdf", width = 4.5, height = 6)
layout(mat = matrix(c(1, 2, 3), nrow = 3, ncol = 1))
# SUB-PLOT 1
forest(
x = dat$estimate,
ci.lb = dat$conf.low,
ci.ub = dat$conf.high,
slab = dat$age_group,
xlab = "mean difference",
cex = 1, cex.lab = 0.7, psize = 1,
xlim = c(-16.7, 11),
alim = c(-3, 4.5),
# ylim = c(0, 71),
ilab = cbind(
dat$I2,
dat$n_studies,
dat$n_g1,
dat$n_g2),
ilab.xpos = c(-10.1, -8.2, -6.1, -3.85),
header = "Age\nGroup"
)
text(-10.65, 6, "I\xB2", font = 2, pos = 4)
text(-8.8, 6, "N\nSt.", font = 2, pos = 4)
text(-7.05, 6, "N\ng1", font = 2, pos = 4)
text(-4.9, 6, "N\ng2", font = 2, pos = 4)
title("sub-plot 1", adj = 0)
# SUB-PLOT 2
forest(
x = dat$estimate,
ci.lb = dat$conf.low,
ci.ub = dat$conf.high,
slab = dat$age_group,
xlab = "mean difference",
cex = 1, cex.lab = 0.7, psize = 1,
xlim = c(-16.7, 11),
alim = c(-3, 4.5),
# ylim = c(0, 71),
ilab = cbind(
dat$I2,
dat$n_studies,
dat$n_g1,
dat$n_g2),
ilab.xpos = c(-10.1, -8.2, -6.1, -3.85),
header = "Age\nGroup"
)
text(-10.65, 6, "I\xB2", font = 2, pos = 4)
text(-8.8, 6, "N\nSt.", font = 2, pos = 4)
text(-7.05, 6, "N\ng1", font = 2, pos = 4)
text(-4.9, 6, "N\ng2", font = 2, pos = 4)
title("sub-plot 2", adj = 0)
# SUB-PLOT 3
forest(
x = dat$estimate,
ci.lb = dat$conf.low,
ci.ub = dat$conf.high,
slab = dat$age_group,
xlab = "mean difference",
cex = 1, cex.lab = 0.7, psize = 1,
xlim = c(-16.7, 11),
alim = c(-3, 4.5),
# ylim = c(0, 71),
ilab = cbind(
dat$I2,
dat$n_studies,
dat$n_g1,
dat$n_g2),
ilab.xpos = c(-10.1, -8.2, -6.1, -3.85),
header = "Age\nGroup"
)
text(-10.65, 6, "I\xB2", font = 2, pos = 4)
text(-8.8, 6, "N\nSt.", font = 2, pos = 4)
text(-7.05, 6, "N\ng1", font = 2, pos = 4)
text(-4.9, 6, "N\ng2", font = 2, pos = 4)
title("sub-plot 3", adj = 0)
dev.off()
可以使用 par 函数的 omi
和 mai
参数来控制它们。我们设置par(mfrow=c(3,1), omi=c(2,.3,.1,.3), mai=c(.5,0,.2,0))
。 omi 指的是整个页面的外边距,mai 指的是每个单独绘图中的内边距。它们总是按照 c(lower, left, upper, right) 的顺序排列;详情请咨询 ?par
。这是我能看到的最好的...
library(metafor)
dat <- read.csv(("https://raw.githubusercontent.com/aelhak/data/main/dat2.csv"))
graphics.off()
grDevices::cairo_pdf("plot.pdf", width = 4.5, height = 6)
par(mfrow=c(3,1), omi=c(2,.3,.1,.3), mai=c(.5,0,.2,0))
# SUB-PLOT 1
forest(
x = dat$estimate,
ci.lb = dat$conf.low,
ci.ub = dat$conf.high,
slab = dat$age_group,
xlab = "mean difference",
cex = .7, cex.lab = 0.7, psize = 1,
xlim = c(-16.7, 11),
alim = c(-3, 4.5),
# ylim = c(0, 71),
ilab = cbind(
dat$I2,
dat$n_studies,
dat$n_g1,
dat$n_g2),
ilab.xpos = c(-10.1, -8.2, -6.1, -3.85),
)
text(-10.65, 6, "I\xB2", font = 2, pos = 4)
text(-8.8, 6, "N\nSt.", font = 2, pos = 4)
text(-7.05, 6, "N\ng1", font = 2, pos = 4)
text(-4.9, 6, "N\ng2", font = 2, pos = 4)
text(-15, 6, "Age", cex=.6)
text(-15, 5.3, "Group", cex=.6)
title("sub-plot 1", adj = 0)
# SUB-PLOT 2
forest(
x = dat$estimate,
ci.lb = dat$conf.low,
ci.ub = dat$conf.high,
slab = dat$age_group,
xlab = "mean difference",
cex = .7, cex.lab = 0.7, psize = 1,
xlim = c(-16.7, 11),
alim = c(-3, 4.5),
# ylim = c(0, 71),
ilab = cbind(
dat$I2,
dat$n_studies,
dat$n_g1,
dat$n_g2),
ilab.xpos = c(-10.1, -8.2, -6.1, -3.85),
)
text(-10.65, 6, "I\xB2", font = 2, pos = 4)
text(-8.8, 6, "N\nSt.", font = 2, pos = 4)
text(-7.05, 6, "N\ng1", font = 2, pos = 4)
text(-4.9, 6, "N\ng2", font = 2, pos = 4)
text(-15, 6, "Age", cex=.6)
text(-15, 5.3, "Group", cex=.6)
title("sub-plot 2", adj = 0)
# SUB-PLOT 3
forest(
x = dat$estimate,
ci.lb = dat$conf.low,
ci.ub = dat$conf.high,
slab = dat$age_group,
xlab = "mean difference",
cex = 1, cex.lab = 0.7, psize = 1,
xlim = c(-16.7, 11),
alim = c(-3, 4.5),
# ylim = c(0, 71),
ilab = cbind(
dat$I2,
dat$n_studies,
dat$n_g1,
dat$n_g2),
ilab.xpos = c(-10.1, -8.2, -6.1, -3.85),
header = "Age\nGroup"
)
text(-10.65, 6, "I\xB2", font = 2, pos = 4)
text(-8.8, 6, "N\nSt.", font = 2, pos = 4)
text(-7.05, 6, "N\ng1", font = 2, pos = 4)
text(-4.9, 6, "N\ng2", font = 2, pos = 4)
title("sub-plot 3", adj = 0)
dev.off()
我正在创建一个包含 3 个部分的图形,这些部分是使用 metafor
包创建的森林图。我怎样才能减少子图之间的白色 space 使它们靠得更近?
这里是示例数据和代码
library(metafor)
dat <- read.csv(("https://raw.githubusercontent.com/aelhak/data/main/dat2.csv"))
graphics.off()
grDevices::cairo_pdf("plot.pdf", width = 4.5, height = 6)
layout(mat = matrix(c(1, 2, 3), nrow = 3, ncol = 1))
# SUB-PLOT 1
forest(
x = dat$estimate,
ci.lb = dat$conf.low,
ci.ub = dat$conf.high,
slab = dat$age_group,
xlab = "mean difference",
cex = 1, cex.lab = 0.7, psize = 1,
xlim = c(-16.7, 11),
alim = c(-3, 4.5),
# ylim = c(0, 71),
ilab = cbind(
dat$I2,
dat$n_studies,
dat$n_g1,
dat$n_g2),
ilab.xpos = c(-10.1, -8.2, -6.1, -3.85),
header = "Age\nGroup"
)
text(-10.65, 6, "I\xB2", font = 2, pos = 4)
text(-8.8, 6, "N\nSt.", font = 2, pos = 4)
text(-7.05, 6, "N\ng1", font = 2, pos = 4)
text(-4.9, 6, "N\ng2", font = 2, pos = 4)
title("sub-plot 1", adj = 0)
# SUB-PLOT 2
forest(
x = dat$estimate,
ci.lb = dat$conf.low,
ci.ub = dat$conf.high,
slab = dat$age_group,
xlab = "mean difference",
cex = 1, cex.lab = 0.7, psize = 1,
xlim = c(-16.7, 11),
alim = c(-3, 4.5),
# ylim = c(0, 71),
ilab = cbind(
dat$I2,
dat$n_studies,
dat$n_g1,
dat$n_g2),
ilab.xpos = c(-10.1, -8.2, -6.1, -3.85),
header = "Age\nGroup"
)
text(-10.65, 6, "I\xB2", font = 2, pos = 4)
text(-8.8, 6, "N\nSt.", font = 2, pos = 4)
text(-7.05, 6, "N\ng1", font = 2, pos = 4)
text(-4.9, 6, "N\ng2", font = 2, pos = 4)
title("sub-plot 2", adj = 0)
# SUB-PLOT 3
forest(
x = dat$estimate,
ci.lb = dat$conf.low,
ci.ub = dat$conf.high,
slab = dat$age_group,
xlab = "mean difference",
cex = 1, cex.lab = 0.7, psize = 1,
xlim = c(-16.7, 11),
alim = c(-3, 4.5),
# ylim = c(0, 71),
ilab = cbind(
dat$I2,
dat$n_studies,
dat$n_g1,
dat$n_g2),
ilab.xpos = c(-10.1, -8.2, -6.1, -3.85),
header = "Age\nGroup"
)
text(-10.65, 6, "I\xB2", font = 2, pos = 4)
text(-8.8, 6, "N\nSt.", font = 2, pos = 4)
text(-7.05, 6, "N\ng1", font = 2, pos = 4)
text(-4.9, 6, "N\ng2", font = 2, pos = 4)
title("sub-plot 3", adj = 0)
dev.off()
可以使用 par 函数的 omi
和 mai
参数来控制它们。我们设置par(mfrow=c(3,1), omi=c(2,.3,.1,.3), mai=c(.5,0,.2,0))
。 omi 指的是整个页面的外边距,mai 指的是每个单独绘图中的内边距。它们总是按照 c(lower, left, upper, right) 的顺序排列;详情请咨询 ?par
。这是我能看到的最好的...
library(metafor)
dat <- read.csv(("https://raw.githubusercontent.com/aelhak/data/main/dat2.csv"))
graphics.off()
grDevices::cairo_pdf("plot.pdf", width = 4.5, height = 6)
par(mfrow=c(3,1), omi=c(2,.3,.1,.3), mai=c(.5,0,.2,0))
# SUB-PLOT 1
forest(
x = dat$estimate,
ci.lb = dat$conf.low,
ci.ub = dat$conf.high,
slab = dat$age_group,
xlab = "mean difference",
cex = .7, cex.lab = 0.7, psize = 1,
xlim = c(-16.7, 11),
alim = c(-3, 4.5),
# ylim = c(0, 71),
ilab = cbind(
dat$I2,
dat$n_studies,
dat$n_g1,
dat$n_g2),
ilab.xpos = c(-10.1, -8.2, -6.1, -3.85),
)
text(-10.65, 6, "I\xB2", font = 2, pos = 4)
text(-8.8, 6, "N\nSt.", font = 2, pos = 4)
text(-7.05, 6, "N\ng1", font = 2, pos = 4)
text(-4.9, 6, "N\ng2", font = 2, pos = 4)
text(-15, 6, "Age", cex=.6)
text(-15, 5.3, "Group", cex=.6)
title("sub-plot 1", adj = 0)
# SUB-PLOT 2
forest(
x = dat$estimate,
ci.lb = dat$conf.low,
ci.ub = dat$conf.high,
slab = dat$age_group,
xlab = "mean difference",
cex = .7, cex.lab = 0.7, psize = 1,
xlim = c(-16.7, 11),
alim = c(-3, 4.5),
# ylim = c(0, 71),
ilab = cbind(
dat$I2,
dat$n_studies,
dat$n_g1,
dat$n_g2),
ilab.xpos = c(-10.1, -8.2, -6.1, -3.85),
)
text(-10.65, 6, "I\xB2", font = 2, pos = 4)
text(-8.8, 6, "N\nSt.", font = 2, pos = 4)
text(-7.05, 6, "N\ng1", font = 2, pos = 4)
text(-4.9, 6, "N\ng2", font = 2, pos = 4)
text(-15, 6, "Age", cex=.6)
text(-15, 5.3, "Group", cex=.6)
title("sub-plot 2", adj = 0)
# SUB-PLOT 3
forest(
x = dat$estimate,
ci.lb = dat$conf.low,
ci.ub = dat$conf.high,
slab = dat$age_group,
xlab = "mean difference",
cex = 1, cex.lab = 0.7, psize = 1,
xlim = c(-16.7, 11),
alim = c(-3, 4.5),
# ylim = c(0, 71),
ilab = cbind(
dat$I2,
dat$n_studies,
dat$n_g1,
dat$n_g2),
ilab.xpos = c(-10.1, -8.2, -6.1, -3.85),
header = "Age\nGroup"
)
text(-10.65, 6, "I\xB2", font = 2, pos = 4)
text(-8.8, 6, "N\nSt.", font = 2, pos = 4)
text(-7.05, 6, "N\ng1", font = 2, pos = 4)
text(-4.9, 6, "N\ng2", font = 2, pos = 4)
title("sub-plot 3", adj = 0)
dev.off()