rr-forestplotmeta-analysis

How to adjust the size of the summary diamonds in the forestplot R package?


The forestplot package in R allows setting styles to modify the color and size of the boxes and for the summary diamonds it seems that only the color (col, fill) can be adjusted, but not the size. I would like to decrease the size of the diamonds but I am not sure how to do that. Here is an example:

# Packages
library(dplyr)
library(tidyr)
library(forestplot)



# Example
forestplot(labeltext = cbind(Author = c("Smith et al", "Smooth et al", "Al et al")),
           mean = cbind(1:3, 1.5:3.5),
           lower = cbind(0:2, 0.5:2.5),
           upper = cbind(4:6, 5.5:7.5),
           is.summary = c(FALSE, FALSE, TRUE),
           vertices = TRUE) |>
  fp_set_style(default = gpar(lineend = "square", linejoin = "mitre", lwd = 1, col = "black"),
               box = gpar(fill = "black", col = "red"), # only one parameter
               lines = list( # as many parameters as CI
                 gpar(lwd = 1), gpar(lwd = 1),
                 gpar(), gpar(),
                 gpar(lwd = 1), gpar(lwd = 1)
               ),
               summary = list( # as many parameters as band per label
                 gpar(fill = "violet", col = "gray", lwd = 1),
                 gpar(fill = "orange", col = "gray", lwd = 1)
               ))

which produces:

enter image description here


Solution

  • You want the following from ?forestplot:

    boxsize Override the default box size based on precision

    The default calculation, which I didn't fully dig through but is based on both the CI width and some text size settings (forestplot:::prepBoxSize), gives roughly 0.1378 for the first two rows and 0.5 for the diamonds (this is internally cast to a matrix).

    Making the third row smaller to taste, adding only this argument to your forestplot call:

    forestplot(..., boxsize=rep(.14, 3)) |>
       ...
    

    forest plot with smaller diamonds