Home > Back-end >  Add a title to the top of multiple plots
Add a title to the top of multiple plots

Time:02-26

How can I add a title at the top of a plot of 6 combined ggplots? I have currently used this code to add a title which places it in the centres of my 6 plots, how would I move it to the top?

Each res_plot here is just a standard ggplot:

all_plots = res_plot1   res_plot2   res_plot3   res_plot4   res_plot5
  
all_plots   ggtitle("Residual Plots")

CodePudding user response:

I am assuming from your syntax that you are using the patchwork package. In that case you can use plot_annotation:

library(patchwork)

res_plot1 <- res_plot2 <- res_plot3 <- res_plot4 <- res_plot5 <- 
  ggplot(mtcars, aes(wt, mpg))   geom_point()

 all_plots <- res_plot1   res_plot2   res_plot3   res_plot4   res_plot5
 
 all_plots   plot_annotation(title = "Residual Plots")

enter image description here

  • Related