【问题标题】:Forest plot with data introduced manually in R在 R 中手动引入数据的森林图
【发布时间】:2020-11-11 08:43:05
【问题描述】:

我最近刚从我的大学收到了一些数据。我被命令创建一个具有优势比的森林图,但主要问题是我无法访问数据集,除了最终值。我只有 OR、95% 置信区间、总体、p 值和变量的 Excel。

我想在 NEJM 上创建一个与此类似的森林图,但我不知道该怎么做。如果有人可以帮助我,我将不胜感激。我看到平台上有类似的问题,但没有一个是针对手动引入的信息而无需进行计算或回归的。

enter image description here

我给你一个链接,指向我想到的图像。

感谢您的帮助。

【问题讨论】:

  • 提供示例数据。森林图不需要数据,只要 OR(CI) 就足够了。
  • 是的,但我想要一个类似的布局。我有所有的数据,但我不知道如何编写代码。

标签: r manual journal forestplot


【解决方案1】:

我和你的情况类似。我只有 OR 和 CI。我创建了以下森林图,将我的数据输入到向量中。您应该检查名为 forestplot 的包及其随附的文档。

test_data <- data.frame(coef1 =c(1.85, 1.86, 1.88, 1.45, 1.64, 1.54, 1.45, 1.64, 1.54, 1.45, 1.64),
                    coef2 =c(1.54, 1.45, 1.64, 1.54, 1.85, 1.86, 1.88, 5.85, 5.86, 5.88, 1.45),
                    coef3 =c(1.64, 1.54, 1.45, 1.64, 1.54, 1.45, 1.64, 1.54, 1.45, 1.64, 1.54),
                    low1  =c(1.45, 1.25, 1.30, 1.10, 1.20, 1.25, 1.15, 1.30, 1.15, 1.15, 1.30),
                    low2  =c(1.15, 1.15, 1.30, 1.15, 1.45, 1.25, 1.30, 3.45, 3.25, 3.30, 1.10),
                    low3  =c(1.20, 1.25, 1.10, 1.20, 1.25, 1.10, 1.20, 1.25, 1.10, 1.20, 1.25),
                    high1 =c(2.52, 2.10, 2.30, 2.54, 2.52, 2.25, 2.54, 2.52, 2.25, 2.54, 2.52),
                    high2 =c(2.25, 3.54, 3.52, 3.25, 2.52, 2.10, 2.30, 7.52, 7.10, 7.30, 2.54),
                    high3 =c(2.52, 2.25, 2.54, 2.52, 2.25, 2.54, 2.52, 2.25, 2.54, 2.52, 2.25))

tabletext<- c("Diabetes", "Heart disease", "Stroke", "COPD", "Asthma", 
"Cancer", "Arthtitis", "Osteoporosis", "Depression", "Severe mental diseases", 
"Dementia")


coef <- with(test_data, cbind(coef1, coef2, coef3))
low <- with(test_data, cbind(low1, low2, low3))
high <- with(test_data, cbind(high1, high2, high3))

library(forestplot)
forestplot(tabletext, coef, low, high,
       title="Comorbidities",
       zero= 1,
       lwd.zero = gpar(lwd=1),
       boxsize=0.18,
       line.margin = .1,
       xticks = c(0:8),
       clip=c(0, 8),
       fn.ci_norm = c(fpDrawNormalCI, fpDrawDiamondCI, fpDrawCircleCI),
       col=fpColors(box=c("darkblue", "darkred", "darkgreen"),
                    line=c("darkblue", "darkred", "darkgreen"),
                    zero = "black"),
       xlab="Odds ratio (95% CI)",
       new_page = TRUE,
       txt_gp = fpTxtGp(label = list(gpar(fontfamily = "Times New Roman", cex=1),
                                     xlab  = gpar(fontfamily = "Times New Roman", cex=1),
                                     ticks = gpar(fontfamily = "Times New Roman", cex=0.8),
                                     title = gpar(fontfamily = "Times New Roman", cex=1.2))),
       legend=c("Unadjusted", "Adjusted for Age and Sex", "Adjusted for all"),
       legend_args = fpLegend(title="Model Adjustment",
                              pos = "top",
                              r=unit(.2, "snpc"),
                              gp = gpar(col="black", fill= "white", lwd=0.7)))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-18
    • 2016-08-17
    • 2018-09-10
    • 1970-01-01
    相关资源
    最近更新 更多