MSKCC-Epi-Bio/bstfun

Forest Plot Integration

jerrodanzalone opened this issue · 7 comments

This is an amazing contribution to reproducible research (as well as just being very user-friendly and comprehensive). I think one enhancement you could make is to offer in-line integration of a forest plot similar to what's traditionally done in meta-analysis. This package does it, but including it here would be great for many projects: https://cran.r-project.org/web/packages/forestplot/vignettes/forestplot.html.


Source

hey hey @jerrodanzalone ! Thanks for the post!

I think it's a great suggestion....the implementation sounds tricky and unclear how to do it 😕 🤓 We're creating tables, and the forest plots usually are a figure that includes the plot and table in one (that I've seen). That doesn't mean we can't make it happen, I am just no expert at combining tables and figures.

  1. We did implement a bay version of forest plots inline, but it has some important limitations....there are no axes, there is no labelling indicating which direction is beneficial/worse. You can take a look here http://www.danieldsjoberg.com/bstfun/reference/add_inline_forest_plot.html
  2. Do you have experience creating the forest plots? Happy to collaborate on a solution!

@ddsjoberg

As you added a plot() method to pass a tbl_regression table to GGally::ggcoel_model, it should be possible to develop a foresplot() method to pass a tbl_regression table to forestplot::foresplot().

A quick and dirty test below (note: just to show faisibility. Some work required to enhance the results and add column label).

library(gtsummary)
library(forestplot)
#> Le chargement a nécessité le package : grid
#> Le chargement a nécessité le package : magrittr
#> Le chargement a nécessité le package : checkmate

tbl <- glm(response ~ age + grade, trial, family = binomial(link = "logit")) %>%
  tbl_regression(exponentiate = TRUE)

forestplot(
  labeltext = tbl %>% as_tibble() %>% as.matrix(),
  mean = c(tbl$table_body$estimate),
  lower = c(tbl$table_body$conf.low),
  upper = c(tbl$table_body$conf.high),
  xlog = tbl$inputs$exponentiate
)

Created on 2021-07-11 by the reprex package (v2.0.0)

@larmarange that is fantastic! I didn't think it would be so seamless :)

I am going to transfer this issue to the bstfun package, and the foresting function(s) can be further developed there. Once we're satisfied with its development there, we can migrate to gtsummary.

Couple of thoughts

  1. Should we implement a new function (perhaps tbl_forest()) that will construct the models stratified by a variable. Then we could write a plot method for it to add the line graphs?
    • implementation could be tbl_strata(~tbl_uvregression(...))...pretty simple
  2. Should we only have a general plot method for forest-type plots, and the users construct the models using the existing functions?

FYI, i like the idea of adding this, but want to let you know i am on a break from development at the moment. Happy to collaborate on something, but i can't take the lead at the moment.

@ddsjoberg Thanks for the quick responses. Enjoy your break from development. I'm not a native R programmer, but I can look into the requirements and see if I have contributions to make. I think both of your suggestions would be fantastic. My current method for accomplishing this is pretty ugly and requires overlaying a plot with spacers to match up with model output. It looks good in print, but is a pain if anything needs to be updated.

On a related note, do you have a preferred citation for use of this?

The more I am thinking about this...i wonder if this would be best as a separate package. We could use the suite of gtsummary functions to prepare the data, and create another suite to create a beautiful forest plot.

There is a pre-print of a gtsummary manuscript here https://journal.r-project.org/archive/2021/RJ-2021-053/ . I am not sure when it will be published officially though.

@ddsjoberg Not sure I see the link with tbl_strata(~tbl_uvregression(...)).

At that step, I have the feeling that it should/could be relatively simple, with a function draw_forestplot() just applied to the result of a tbl_regression(), showing the table as it has been built with classical gtsummary functions.

The tbl_strata(~tbl_uvregression(...)) functions are helpful for constructing the plots in the original post.

I guess I am torn between adding simple integration for gtsummary and a forest plotting package. I think much of the customization in gtsummary may be lost this way. Or should I just write one myself...or perhaps get in touch with a package maintainer to ensure gtsummary integration....