Search code examples
rr-forestplot

Changing Size of Squares in forest plot R


I'm new to R and am making some forest plots. I have figured out how to make them using the following code:

library(forestplot)
library(rmeta)

jpeg("test21.jpeg", units = "in", width = 7, height = 7, res = 100)

forestplot(tabletext2, 
        mean = for_forest$median, lower = for_forest$lower, upper = for_forest$upper,
           xlog = FALSE,
        clip = c(-0.006,0.002),
        xticks = c(-0.0006,-0.0004,-0.0002,0,0.0002),
        zero = 0,
           col = fpColors(box = "royalblue",
                          line = "darkblue",
                          summary = "royalblue"))



dev.off()

And I get a decent looking output:

enter image description here

But how do I make the boxes that represent the median all the same size? It seems that more negative medians are smaller boxes while less negative medians are bigger boxes. So the magnitude of the median is represented 2 ways, with the position along the line and with its size which is somewhat confusing.

Also how would I make the lines thicker?

Thanks!


Solution

  • In general you should provide enough data to create a Minimal Reproducible Example we can debug.

    However, looking at the Package Documentation it says that the boxsize is based on precision, and can be overwritten using the boxsize argument. Without sample data to test, I can only give a possible answer, but looking at the examples in the documentation, try adding boxsize = 0.25

    Also there, it says the line widths are set in shapes_gp. So try adding shapes_gp = fpShapesGp(default = gpar(lwd = 3))

    forestplot(tabletext2, 
               mean = for_forest$median, lower = for_forest$lower, upper = for_forest$upper,
               xlog = FALSE,
               clip = c(-0.006,0.002),
               xticks = c(-0.0006,-0.0004,-0.0002,0,0.0002),
               zero = 0,
               col = fpColors(box = "royalblue",
                              line = "darkblue",
                              summary = "royalblue"),
               boxsize = 0.25,
               shapes_gp = fpShapesGp(default = gpar(lwd = 3)))
    

    If this doesn't work please send some data for a Minimal Reproducible Example I can debug here.