如何向森林图中添加文本

How to add text to forest plots

我正在尝试使用这个包含三列的数据框创建森林图:studies 是研究的名称,n 是研究中的样本数,accuracy 是 % 准确度:

> dput(for.meta)
structure(list(studies = structure(c(11L, 5L, 13L, 3L, 14L, 12L, 
4L, 6L, 8L, 2L, 10L, 1L, 7L, 9L), .Label = c("EMTAB292", "GSE10327", 
"GSE12992", "GSE21140", "GSE30074", "GSE37382", "GSE41842", "GSE49243", 
"GSE50161", "GSE50765", "GSE62803", "GSE67850", "GSE73038", "GSE74195"
), class = "factor"), n = c(8L, 30L, 46L, 40L, 30L, 22L, 103L, 
50L, 58L, 62L, 12L, 19L, 19L, 24L), accuracy = c(85.71, 93.3, 
93.3, 94.9, 95, 95.5, 96.8, 97.8, 98.3, 98.3, 100, 100, 100, 
100), label = c("GSE62803 (n = 8)", "GSE30074 (n = 30)", "GSE73038 (n = 46)", 
"GSE12992 (n = 40)", "GSE74195 (n = 30)", "GSE67850 (n = 22)", 
"GSE21140 (n = 103)", "GSE37382 (n = 50)", "GSE49243 (n = 58)", 
"GSE10327 (n = 62)", "GSE50765 (n = 12)", "EMTAB292 (n = 19)", 
"GSE41842 (n = 19)", "GSE50161 (n = 24)")), row.names = c("GSE62803", 
"GSE30074", "GSE73038", "GSE12992", "GSE74195", "GSE67850", "GSE21140", 
"GSE37382", "GSE49243", "GSE10327", "GSE50765", "EMTAB292", "GSE41842", 
"GSE50161"), class = "data.frame")

这是创建森林图的代码:

library(metafor)
colfunc <- colorRampPalette(c("red", "darkred"))
metafor::forest(for.meta$accuracy, for.meta$n, 
                slab = for.meta$label, cex=.9,
                xlab = "Accuracy (%)", col = colfunc(14), 
                main = "Accuracy across 14 datasets\n(Median = 97.3%)", top = 3, refline = 97)
text(x = 70, y = 50, "Dataset", pos=4)
text(x = 90, y = 75, "Accuracy", pos = 3, font = 4)

绘图已创建,但数据集列和准确性列没有显示文本(顶部的标签)。

您添加的文本的 y 轴位置太大。这应该有效:

metafor::forest(for.meta$accuracy, for.meta$n, 
                slab = for.meta$label, cex=.9,
                xlab = "Accuracy (%)",
                main = "Accuracy across 14 datasets\n(Median = 97.3%)", top = 3,
                refline = 97,
                xlim = c(30, 165))

text(x =  30, y = 16, "Dataset",  pos=4)
text(x = 165, y = 16, "Accuracy", pos = 2, font = 4)

请注意,我在森林图中设置了 x 轴范围,这样可以更轻松地为要添加的文本设置相同的范围。此外,我必须删除 col=colfunc(14) 才能将其变为 运行。不确定该函数的来源。