How do I create subgroups on a forest plot in R?

40 Views Asked by At

I want to re-organize my forest plot to contain subgroups wherein each race/ethnicity has SPBs listed underneath it.

Example:
Race/Ethnicity    Adjusted OR           Graphical Representation of OR
Hispanic/Latino
   Any SPB         3.21 (2.66, 3.90)
   Sunscreen       2.00 (1.50, 2.50)    
Black
   Any SPB        4.09 (3.34, 5.05)
   Sunscreen      2.00 (1.50, 2.50)
Asian
   Any SPB        3.96 (2.97, 5.39)
   Sunscreen      2.00 (1.50, 2.50)
NA/AN
   Any SPB        1.04 (0.72, 1.55)
   Sunscreen      2.00 (1.50, 2.50)
Multiracial
   Any SPB        2.82 (1.68, 5.13)
   Sunscreen      2.00 (1.50, 2.50)

I looked through the introduction to forest plots handbook, but I could not figure out how to code for this.

Here is my code so far and the resulting forest plot:

base_data <- tibble::tibble(mean = c(3.21, 4.09, 3.96, 1.04, 2.82, 2.00, 2.00, 2.00, 2.00, 2.00),
                            lower = c(2.66, 3.34, 2.97, 0.72, 1.68, 1.50, 1.50, 1.50, 1.50, 1.50),
                            upper = c(3.90, 5.05, 5.39, 1.55, 5.13, 2.50, 2.50, 2.50, 2.50, 2.50),
                            anyspb = c("Any SPB", "Any SPB", "Any SPB", "Any SPB", "Any SPB", "Sunscreen", "Sunscreen", "Sunscreen", "Sunscreen", "Sunscreen"),
                            race = c("Hispanic/Latino", "Black", "Asian", "NA/AN", "Multiracial", "Hispanic/Latino", "Black", "Asian", "NA/AN", "Multiracial"),
                            aOR = c("3.21 (2.66, 3.90)", "4.09 (3.34, 5.05)", "3.96 (2.97, 5.39)", "1.04 (0.72, 1.55)", "2.82 (1.68, 5.13)", "2.00 (1.50, 2.50)", "2.00 (1.50, 2.50)", "2.00 (1.50, 2.50)", "2.00 (1.50, 2.50)", "2.00 (1.50, 2.50)"))


base_data |>
  forestplot(labeltext = c(race, anyspb, aOR),
             clip = c(0.1, 7.5),
             xlog = TRUE) |>
  fp_set_style(box = "black",
               line = "black") |>
  fp_add_header(race = c("Race/Ethnicity"),
                anyspb = c("SPB"),
                aOR = c("Adjusted OR")) 

Forest plot from code

Also, how do I save a high-resolution version of the forest plot image? I'm having trouble with:

tiff("Any_SPB_Forest_Plot.tiff", compression = "lzw")

Thanks so much for all your help!

0

There are 0 best solutions below