rr-forestplot

r-forestplot reduce space between rows


I would like to minimise the height of the rows so that it is consistent across different forrest plots which have varying numbers of rows.

I have tried lineheight = unit(8.6,"mm") but it doesn't seem to work

library(forestplot)

base_data <- tibble::tibble(mean  = c(0.578, 0.165),
                            lower = c(0.372, 0.018),
                            upper = c(0.898, 1.517),
                            study = c("Auckland", "Block"),
                            deaths_steroid = c("36", "1"),
                            deaths_placebo = c("60", "5"),
                            OR = c("0.58", "0.16"))

base_data |>
  forestplot(labeltext = c(study, deaths_steroid, deaths_placebo, OR),
             clip = c(0.1, 2.5),
             xlog = TRUE) |>
  fp_set_style(box = "royalblue",
               line = "darkblue",
               summary = "royalblue") |> 
  fp_add_header(study = c("", "Study"),
                deaths_steroid = c("Deaths", "(steroid)"),
                deaths_placebo = c("Deaths", "(placebo)"),
                OR = c("", "OR")) |>
  fp_append_row(mean  = 0.531,
                lower = 0.386,
                upper = 0.731,
                study = "Summary",
                OR = "0.53",
                is.summary = TRUE) |> 
  fp_set_zebra_style("#EFEFEF") ```

Solution

  • There is an open issue with the lineheight argument, but there is a patch in the development branch you might try. First install the development version:

    devtools::install_github("gforge/forestplot@develop")
    

    Then we can test if the patch fixes the issue with lineheight:

    20mm as a Test

    library(forestplot)
    
    base_data <- tibble::tibble(mean  = c(0.578, 0.165),
                                lower = c(0.372, 0.018),
                                upper = c(0.898, 1.517),
                                study = c("Auckland", "Block"),
                                deaths_steroid = c("36", "1"),
                                deaths_placebo = c("60", "5"),
                                OR = c("0.58", "0.16"))
    
    base_data |>
      forestplot(labeltext = c(study, deaths_steroid, deaths_placebo, OR),
                 clip = c(0.1, 2.5),
                 lineheight =  unit(20,"mm"),
                 xlog = TRUE) |>
      fp_set_style(box = "royalblue",
                   line = "darkblue",
                   summary = "royalblue") |> 
      fp_add_header(study = c("", "Study"),
                    deaths_steroid = c("Deaths", "(steroid)"),
                    deaths_placebo = c("Deaths", "(placebo)"),
                    OR = c("", "OR")) |>
      fp_append_row(mean  = 0.531,
                    lower = 0.386,
                    upper = 0.731,
                    study = "Summary",
                    OR = "0.53",
                    is.summary = TRUE) |> 
      fp_set_zebra_style("#EFEFEF")
    

    8.6mm as Desired

    base_data |>
      forestplot(labeltext = c(study, deaths_steroid, deaths_placebo, OR),
                 clip = c(0.1, 2.5),
                 lineheight =  unit(8.6,"mm"),
                 xlog = TRUE) |>
      fp_set_style(box = "royalblue",
                   line = "darkblue",
                   summary = "royalblue") |> 
      fp_add_header(study = c("", "Study"),
                    deaths_steroid = c("Deaths", "(steroid)"),
                    deaths_placebo = c("Deaths", "(placebo)"),
                    OR = c("", "OR")) |>
      fp_append_row(mean  = 0.531,
                    lower = 0.386,
                    upper = 0.731,
                    study = "Summary",
                    OR = "0.53",
                    is.summary = TRUE) |> 
      fp_set_zebra_style("#EFEFEF")
    

    Created on 2024-04-22 with reprex v2.1.0