如何在不移动其余文本的情况下移动 metafor 图?

How can I move the metafor plot without moving the rest of the text?

我正在尝试使用 metafor 包使我的森林图以白色 space 为中心。我试图只移动情节而不移动文本列。有没有人有什么建议?该图使用带有 metafor 包的 forest() 函数进行编码。


library(metafor)

labela <- as.character(c("Sex (male vs. female)", "   50 to <60", "   60", 
                         "   <18.5", "   25 to <30", "   30 to <35", "   35 to <40", 
                         "   40", "Cancer diagnosis (yes vs. no)", "   Previous", "   Current", 
                         "   Special occasions only", "   One to three times a month", 
                         "   Once or twice a week", "   Three or four times a week", 
                         "   Daily or almost daily", "Oral contraceptive pill (ever vs. never)", 
                         "Hormone replacement therapy (ever vs. never)", "Fracture in the last 5 years (yes vs. no)", "Previous deep vein thrombosis (yes vs. no)", "Previous pulmonary embolism (yes vs. no)"))
labela <- factor(labela, levels = unique(labela))
hazardsa <- log(c(1.44, 1.57, 2.46, 0.78, 1.35, 1.78, 2.29, 3.30, 1.58, 1.03, 1.24, 0.99, 0.87, 0.89, 0.74, 0.80, 0.88, 1.07, 1.19, 3.34, 1.82))
lowera <- log(c(1.29, 1.41, 2.22, 0.43, 1.25, 1.62, 2.02, 2.81, 1.45, 0.96, 1.12, 0.87, 0.76, 0.79, 0.65, 0.71, 0.79, 0.97, 1.08, 2.96, 1.51))
uppera <- log(c(1.60, 1.75, 2.73, 1.40, 1.47, 1.95, 2.60, 3.88, 1.73, 1.10, 1.36, 1.12, 0.99, 1.00, 0.83, 0.90, 0.99, 1.18, 1.31, 3.77, 2.20))
patient_numa <- c(229134, 167158, 217493, 2626, 212127, 87557, 24994, 9704, 41700, 173070, 52979, 58012, 55858, 129297, 115445, 101774, 220446, 103919, 47466, 9323, 3955)
event_numa <- c(2685, 1347, 2935, 11, 2007, 1145, 415, 227, 674, 1863, 572, 675, 525, 1252, 937, 985, 1565, 1030, 559, 440, 175)
pa <- c("<0.001", NA, NA, NA, NA, NA, NA, NA, "<0.001","0.47", "<0.001", "0.87", "0.04", "0.05", "<0.001", "<0.001", "0.03", "0.15", "<0.001", "<0.001", "<0.001")
forestplota <- data.frame(labela, hazardsa, lowera, uppera, event_numa, patient_numa, pa)
forestplota$patient_numa <- rev(forestplota$patient_numa)

par(mar=c(4,4,1,2))
pdf(file = "figure1.pdf", width = 15, height = 8.5)
pdf.options(encoding='ISOLatin2.enc')
forest(rev(hazardsa), ci.lb = rev(lowera), ci.ub = rev(uppera), slab = rev(labela), xlim = c(-5,7), 
       xlab = "Adjusted Hazard Ratio for Venous Thromboembolism Event", 
       refline = 0, annotate = T, ylim = c(-1, 29), ilab = cbind(forestplota$patient_numa, rev(event_numa), rev(pa)), 
       ilab.xpos=c(-1,-0.25, 6.5), at = log(c(0.25, 0.5, 1, 2, 4, 6)), rows = c(2:11,13:14, 16:21, 23:24,26), 
       cex = 1, yaxs = "i", textpos = c(NA, 6), atransf = exp)
text(-5, 27.29, pos = 4, "Variable")
text(-1.3, 27.67, pos = 4, "No. of \nPatients")
text(-0.5, 27.67, pos = 4, "No. of \nEvents")
text(4.82, 27.69, pos = 4, "Hazard Ratio \n(95% CI)")
text(6.2, 27.32, pos = 4, "P-value")
text(6.21, 23.5, pos = 4, "<0.001")
text(6.21, 19, pos = 4, "<0.001")

text(-5, c(25, 22, 15, 12), pos=4, c("Age, years (vs. <50)", "Body mass index* (vs. 18.5 to <25)", "Smoking (vs. never)", "Alcohol (vs. never)"))
dev.off()


您需要调整xlim = c(-5,7)。也许 xlim = c(-8,5) 然后当然你需要调整其他位置,比如 ilab.xpos=c(-4, -2.25, 4.5)textpos = c(NA, 4),然后调整其余位置。

P.S.: par(mar=c(4,4,1,2)) 应该放在 pdf() [...] dev.off() 部分里面。

这是我的尝试:真的很难。有很多事情你必须手工完成。如果你改变一件事,其他人也会改变。不是很容易理解。 主要调整是通过调整 xlim 和添加 alim 完成的。 ilab.xpos=需要调整以及text个位置:

library(metafor)

labela <- as.character(c("Sex (male vs. female)", "   50 to <60", "   60", 
                         "   <18.5", "   25 to <30", "   30 to <35", "   35 to <40", 
                         "   40", "Cancer diagnosis (yes vs. no)", "   Previous", "   Current", 
                         "   Special occasions only", "   One to three times a month", 
                         "   Once or twice a week", "   Three or four times a week", 
                         "   Daily or almost daily", "Oral contraceptive pill (ever vs. never)", 
                         "Hormone replacement therapy (ever vs. never)", "Fracture in the last 5 years (yes vs. no)", "Previous deep vein thrombosis (yes vs. no)", "Previous pulmonary embolism (yes vs. no)"))
labela <- factor(labela, levels = unique(labela))
hazardsa <- log(c(1.44, 1.57, 2.46, 0.78, 1.35, 1.78, 2.29, 3.30, 1.58, 1.03, 1.24, 0.99, 0.87, 0.89, 0.74, 0.80, 0.88, 1.07, 1.19, 3.34, 1.82))
lowera <- log(c(1.29, 1.41, 2.22, 0.43, 1.25, 1.62, 2.02, 2.81, 1.45, 0.96, 1.12, 0.87, 0.76, 0.79, 0.65, 0.71, 0.79, 0.97, 1.08, 2.96, 1.51))
uppera <- log(c(1.60, 1.75, 2.73, 1.40, 1.47, 1.95, 2.60, 3.88, 1.73, 1.10, 1.36, 1.12, 0.99, 1.00, 0.83, 0.90, 0.99, 1.18, 1.31, 3.77, 2.20))
patient_numa <- c(229134, 167158, 217493, 2626, 212127, 87557, 24994, 9704, 41700, 173070, 52979, 58012, 55858, 129297, 115445, 101774, 220446, 103919, 47466, 9323, 3955)
event_numa <- c(2685, 1347, 2935, 11, 2007, 1145, 415, 227, 674, 1863, 572, 675, 525, 1252, 937, 985, 1565, 1030, 559, 440, 175)
pa <- c("<0.001", NA, NA, NA, NA, NA, NA, NA, "<0.001","0.47", "<0.001", "0.87", "0.04", "0.05", "<0.001", "<0.001", "0.03", "0.15", "<0.001", "<0.001", "<0.001")
forestplota <- data.frame(labela, hazardsa, lowera, uppera, event_numa, patient_numa, pa)
forestplota$patient_numa <- rev(forestplota$patient_numa)

par(mar=c(4,4,1,2))
pdf(file = "figure1.pdf", width = 15, height = 8.5)
pdf.options(encoding='ISOLatin2.enc')
forest(rev(hazardsa), ci.lb = rev(lowera), ci.ub = rev(uppera), slab = rev(labela), xlim = c(-11,8), alim = c(-11,8),
       xlab = "Adjusted Hazard Ratio for Venous Thromboembolism Event", 
       refline = 0, annotate = T, ylim = c(-1, 29), ilab = cbind(forestplota$patient_numa, rev(event_numa), rev(pa)), 
       ilab.xpos=c(-5.5,-4.25, 6.5), at = log(c(0.25, 0.5, 1, 2, 4, 6)), rows = c(2:11,13:14, 16:21, 23:24,26), 
       cex = 1, yaxs = "i", textpos = c(NA, 6), atransf = exp)
text(-11, 27.29, pos = 4, "Variable")
text(-6, 27.67, pos = 4, "No. of \nPatients")
text(-4.6, 27.67, pos = 4, "No. of \nEvents")
text(4.22, 27.69, pos = 4, "Hazard Ratio \n(95% CI)")
text(6, 27.32, pos = 4, "P-value")
text(6, 23.5, pos = 4, "<0.001")
text(6, 19, pos = 4, "<0.001")

text(-11, c(25, 22, 15, 12), pos=4, c("Age, years (vs. <50)", "Body mass index* (vs. 18.5 to <25)", "Smoking (vs. never)", "Alcohol (vs. never)"))
dev.off()