Brad Brad - 1 month ago 8
R Question

Forest plot doesn't match the sidetable

I have to do a forestplot and the sidetable, but instead of using Odds Ratio (as usual) I have to use the effect size. I wrote this code based on another that I found on Internet because I need the forestplot and the sidetable. I edited my question to include example data and my partial solution.

library(forestplot)


####With this I create the data for the tabletext###
TE<-as.character(c(-0.05, 0.27, 0.39, 0.21, 0, 0.08, 0.28, 0.23, -0.16, 0.11, 0.13,
0.03, 0.78, 0.43, 0.07, 0.34, 0.58))
Inferior<-as.character(c(-0.55, -0.22, -0.11, -0.3, -0.31, -0.22, -0.03, -0.07, -0.47,
-0.19, -0.18, -0.27, 0.46, 0.12, -0.55, -0.07, 0.15))
Superior<-as.character(c(0.44, 0.76, 0.88, 0.73, 0.31, 0.39, 0.6, 0.54, 0.15, 0.42,
0.45, 0.34, 1.11, 0.74, 0.69, 0.75, 1.02))
Autor<-c("Cain & Smith", "Cain & Smith", "Cain & Smith", "Cain & Smith",
"Hoffman & Dangl", "Hoffman & Dangl", "Hoffman & Dangl", "Hoffman & Dangl",
"Hoffman & Dangl", "Hoffman & Dangl", "Hoffman & Dangl", "Hoffman & Dangl",
"Hoffman & Dangl", "Hoffman & Dangl", "Bunch", "Bunch", "Bunch")

###With this I create the values for the forest plot###
TE2<-c(NA, -0.05, 0.27, 0.39, 0.21, 0, 0.08, 0.28, 0.23, -0.16, 0.11, 0.13,
0.03, 0.78, 0.43, 0.07, 0.34, 0.58, NA, NA)
Inferior2<-c(NA, -0.55, -0.22, -0.11, -0.3, -0.31, -0.22, -0.03, -0.07, -0.47,
-0.19, -0.18, -0.27, 0.46, 0.12, -0.55, -0.07, 0.15, NA, NA)
Superior2<-c(NA, 0.44, 0.76, 0.88, 0.73, 0.31, 0.39, 0.6, 0.54, 0.15, 0.42, 0.45,
0.34, 1.11, 0.74, 0.69, 0.75, 1.02, NA, NA)

###With this I create the sidetable###
tabletext<-cbind(
c("Autor", Autor, NA, "Summary"),
c("Effect Size", TE, NA, NA),
c("Inferior", Inferior, NA, NA),
c("Superior", Superior, NA, "0.17"))

###With this I create the forestplot###
forestplot(tabletext,
hrzl_lines = gpar(col="#444444"),
mean = TE2, lower = Inferior2, upper = Superior2,
new_page = TRUE,
xlog=FALSE,
is.summary=c(TRUE, rep(FALSE,18), TRUE),
graph.pos=5,
boxsize=0.2,
col=fpColors(box="black",line="black", summary="black"))


My former problem was that the resulting forestplot moves the effect sizes one row up (so, they didn´t match the info on the sidetable because begins at the column titles level). Now, my only problem is that it doesn´t add the summary to the plot.

I will really appreciate all your help!

Answer

Your problem is that you haven't added the summary information to the mean, upper & lower confidence intervals:

library(forestplot)
####With this I create the data for the tabletext###
TE<-as.character(c(-0.05, 0.27, 0.39, 0.21, 0, 0.08, 0.28, 0.23, -0.16, 0.11, 0.13,
                   0.03, 0.78, 0.43, 0.07, 0.34, 0.58))
Inferior<-as.character(c(-0.55, -0.22, -0.11, -0.3, -0.31, -0.22, -0.03, -0.07, -0.47,
                         -0.19, -0.18, -0.27, 0.46, 0.12, -0.55, -0.07, 0.15))
Superior<-as.character(c(0.44, 0.76, 0.88, 0.73, 0.31, 0.39, 0.6, 0.54, 0.15, 0.42, 
                         0.45, 0.34, 1.11, 0.74, 0.69, 0.75, 1.02))
Autor<-c("Cain & Smith", "Cain & Smith", "Cain & Smith", "Cain & Smith", 
         "Hoffman & Dangl", "Hoffman & Dangl", "Hoffman & Dangl", "Hoffman & Dangl",
         "Hoffman & Dangl", "Hoffman & Dangl", "Hoffman & Dangl", "Hoffman & Dangl",
         "Hoffman & Dangl", "Hoffman & Dangl", "Bunch", "Bunch", "Bunch")

###With this I create the values for the forest plot###
TE2<-c(NA, -0.05, 0.27, 0.39, 0.21, 0, 0.08, 0.28, 0.23, -0.16, 0.11, 0.13,
       0.03, 0.78, 0.43, 0.07, 0.34, 0.58, NA, NA)
Inferior2<-c(NA, -0.55, -0.22, -0.11, -0.3, -0.31, -0.22, -0.03, -0.07, -0.47,
             -0.19, -0.18, -0.27, 0.46, 0.12, -0.55, -0.07, 0.15, NA, NA)
Superior2<-c(NA, 0.44, 0.76, 0.88, 0.73, 0.31, 0.39, 0.6, 0.54, 0.15, 0.42, 0.45,
             0.34, 1.11, 0.74, 0.69, 0.75, 1.02, NA, NA)

###With this I create the sidetable###
tabletext<-cbind(
  c("Autor", Autor, NA, "Summary"),
  c("Effect Size", TE, NA, NA),
  c("Inferior", Inferior, NA, NA),
  c("Superior", Superior, NA, "0.17"))

# Add this!
TE2[20] <- .17
Inferior2[20] <- TE2[20] - .3
Superior2[20] <- TE2[20] + .3

###With this I create the forestplot###
forestplot(tabletext, 
           hrzl_lines = gpar(col="#444444"),
           mean = TE2, lower = Inferior2, upper = Superior2, 
           new_page = TRUE,
           xlog=FALSE,
           is.summary=c(TRUE, rep(FALSE,18), TRUE),
           graph.pos=5,
           boxsize=0.2,
           col=fpColors(box="black",line="black", summary="black"))

enter image description here