How to use estimate in forestplot package?

196 Views Asked by At

I'm trying to use the forestplot package to include estimate (beta) values. I can do it just fine if I were to use means instead of estimates using the code below:

library(forestplot)
library(dplyr)

tabletext <- cbind(c("", "Group", "A", "At 1M", "At 3M", "At 6M", "B", "A1 1M", "At 3M", "At 6M", "C", "At 1M", "At 3M", "At 6M"),
               c("Mean", "", "", "0.11", "0.11", "0.0062", "", "0.17", "0.24", "0.22", "", "0.081", "0.11", "0.014"),
               c("Lower CI", "", "", "0.22", "0.28", "0.48", "", "0.16", "0.17", "0.26", "", "0.26", "0.27", "0.51"),
               c("Upper CI", "", "", "0.45", "0.51", "0.49", "", "0.52", "0.64", "0.71", "", "0.43", "0.69", "0.48"))
fp <- structure(list(mean  = c(NA, NA, NA, 0.11, 0.11, 0.0062, NA, 0.17, 0.24, 0.22, NA, 0.081, 0.11, 0.014), 
                                  lower = c(NA, NA, NA, 0.22, 0.28, 0.48, NA, 0.16, 0.17, 0.26, NA, 0.26, 0.27, 0.51),
                                  upper = c(NA, NA, NA, 0.45, 0.51, 0.49, NA, 0.52, 0.64, 0.71, NA, 0.43, 0.69, 0.48)),
                             .Names = c("mean", "lower", "upper"), 
                             row.names = c(NA, -14L),
                             class = "data.frame")
fp2<-fp %>% 
  forestplot(labeltext = tabletext, 
         clip = c(0.005, 1), 
         xlog = TRUE, 
         col = fpColors(box = "royalblue",
                        line = "darkblue"))

However, I'm not quite sure how to modify the code to use estimates instead. The code above doesn't work for estimates because some of my values are negative. I'm trying to get an outcome similar to the figure I have attached. Any help would be greatly appreciated!

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

I agree with the comment above, mean values lying out of data range are inexplicable. Perhaps it's not mean but some other measure? (Sorry about that. These values depict CI. The estimate can certainly be out of confidence interval.My fault.)

Anyway, I can spot the reason why these values are not showing on the plot. The xlog parameter is converting xtics to logarithmic values( which are -ve for the decimal values) and the clip parameter is clipping out anything less than 0.005

Switching off Xlog will mark the values in the plot :

fp %>% 
  forestplot(labeltext = tabletext, 
             clip = c(0, 1), 
             xlog = F, 
             col = fpColors(box = "royalblue",
                            line = "darkblue"))
     

Edit Note: I've edited code to borrow proper labels from tabletext