Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in R Programming by (50.2k points)

With the help of the objects that are being saved from the stat summary of models, I want to plot a forest using the metafor package. in my object, there will be 5 columns: Group, subgroups, estimate, the upper limit, and lower limit CI, which looks like the following:

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?

1 Answer

0 votes
by (108k points)

I think you should use the forestplot package. First, you need to pivot it wide, and then plot it like the following:

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"))

            )

If you want to know more about R then do check out the R programming tutorial

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...