10.5 Customizing and saving your risk of bias plots

10.5.1 The ggplot2 package

Both robvis functions (rob_summary() and rob_traffic_light()) produce a ggplot object, and so can be customized and saved using functions from the ggplot2 package. Use the following code to load this package:

library(ggplot2)

10.5.2 Modifying your plots

There are a range of post-production modifications you can make to you plots using ggplot2 functions. A useful example is adding a title to the plot:

# Make sure you have the ggplot2 package installed and loaded

rob_summary(data_rob2, "ROB2") +
  ggtitle("Your custom title")

In a similar manner, you can add a border to your plots:

# Make sure you have the ggplot2 package installed and loaded

rob_summary(data_rob2, "ROB2") +
   theme(plot.background = element_rect(colour = "black"))

10.5.3 Saving the plot

In order to save a risk of bias plot, we first assign it to an object using the <- operator and then save it using the ggsave() function of the ggplot2

When saving the summary barplot, we recommend using the following code, with the default height and width values.

# Create your plot, and assign it to an object
rob_barplot <- rob_summary(data_rob2, "ROB2")

# Save your plot
ggsave(plot = rob_barplot,                  # Plot object to save
       filename = "robplot2.png",     # Destination file
       width = 8,                           # Width of image (recommended)
       height = 2.41,                       # Height of image (recommended)
       dpi = 1000                           # Resolution of image
       )

When saving the traffic light plots, the approach is the same. However, there are no recommended values for the width and height parameters, as the best values for these parameters will vary from plot to plot as the number and names of included studies change.

10.5.4 Saving in a different format

The plots can be saved in a range of formats using the function outlined above, simply by changing the extension of the file-name (e.g. from “.png” to “.pdf”). Acceptable formats included:

  • .png
  • .pdf
  • .tiff
  • .svg1

For example, to save the barplot created above (rob_barplot) as a PDF:

# Save your plot
ggsave(plot = rob_barplot,                  
       filename = "robplot2.pdf",     # File extension now ".pdf"
       width = 8,                           
       height = 2.41,                       
       dpi = 1000                           
       )




  1. This format requires you to install and load the svglite package: install.packages("svglite"); library(svglite)

banner