简体   繁体   English

R - 如何使用 metafor package plot 森林 plot?

[英]R - How to plot forest plot using metafor package?

I would like to plot a forest plot using objects saved from stat summary of models using the metafor package. in my object, there will be 5 columns: Group, sub groups, estimate, upper limit and lower limit CI, which looks like the following:我想 plot 森林 plot 使用从模型统计摘要中保存的对象,使用 metafor package。在我的 object 中,将有 5 列:组、子组、估计、上限和下限 CI,如下所示:

Group Subgroup  est   lCI hCI
A         1     0.2    ~   ~
A         2     0.3    ~   ~
A         3     0.8    ~   ~
B         1      ~     ~   ~
B         2      ~     ~   ~
B         3      ~     ~   ~

How can I plot a forest post that group the subgroups together and categorise as such?我怎样才能 plot 将子组组合在一起并进行分类的森林帖子? With the CI as error bars.以 CI 作为错误栏。

Thank you!谢谢!

I have only used the forestplot package before, you need to pivot it wide first, and plot it like something below:我以前只用过森林图forestplot ,你需要先把它加宽 pivot,然后把它加宽 plot,如下所示:

library(forestplot)
library(tidyr)
library(dplyr)

results = data.frame(Group=rep(c("A","B"),each=3),
Subgroup = rep(1:3,2),est = runif(6,min=-2,max=2))

results$lCI = results$est - 0.1
results$hCI = results$est + 0.1

df_wide = pivot_wider(results,id_cols=Group,names_from=Subgroup,values_from=c("est","lCI","hCI"))

forestplot(list(Var=df_wide[["Group"]]), 
           legend = 1:3,
           fn.ci_norm = c(fpDrawNormalCI, fpDrawCircleCI),
           mean = select(df_wide,contains("est")),
           lower = select(df_wide,contains("lCI")),
           upper = select(df_wide,contains("hCI")),
           col=fpColors(box=c("blue", "darkred"))
            )

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM