Hi I am trying to add a main title to a group of plots I made using the ggarrange function.
Each plot has a title but I need a main title for both figures. Something like "Plot 1: Distribution by gender" over figure 1 and 2.
Here is my code.
library(tidyverse)
library(ggpubr)
my_data_2018 <- tibble(Var = c(900, 1500, 350, 1200, 750, 100,125,250,300),
Gender = c("W", "W", "W", "M", "M", "W", "W", "M", "W"),
my_weights_2018 = c(2.2, 3.1, 8.2, 4.2, 5.3, 6.8, 12, 25, 1))
my_data_2019 <- tibble(Var = c(32, 21, 21, 900, 1500, 350, 1200, 750, 100,125,250,300),
Gender = c("W", "W", "W","W", "W", "W", "M", "M", "W", "W", "M", "W"),
my_weights_2019 = c(2.2, 3.1, 8.2, 2.2, 3.1, 8.2, 4.2, 5.3, 6.8, 12, 25, 1))
my_data_2018 %>%
ggplot(aes(Var, Gender, weight = my_weights_2018, fill = Gender))+
geom_violin(color = "black", scale = "count")+
ggtitle("Figure 1")+
theme(legend.position = "none")-> plot_1
my_data_2019 %>%
ggplot(aes(Var, Gender, weight = my_weights_2019, fill = Gender))+
geom_violin(color = "black", scale = "count")+
ggtitle("Figure 2")+
theme(legend.position = "none")-> plot_2
ggarrange(plot_1, plot_2)