Add main title multiple plots ggarange
10,507
You can use annotate_figure
:
library(ggpubr)
plot<- ggarrange(ba,mi,fa, ncol=3, nrow=1, common.legend = TRUE,legend="bottom")
annotate_figure(plot, top = text_grob("Dive depths (m)",
color = "red", face = "bold", size = 14))
Author by
Érika Soares Coelho
Updated on July 24, 2022Comments
-
Érika Soares Coelho almost 2 years
I have one data frame
dt
with data about dive behavior and at three different areasBA, MI, FA
. I want to add main title to my multiple plots (ba, mi, fa
) usingggarrange
, but I didn't find something that worked. I want to add main title "Dive depths (m)" at top of my 3 plotslibrary(data.table) library(ggplot2) dt = data.table(area= c("BA", "FA", "MI"), dmean = c(30, 50, 200, 76, 467, 87, 98, 10, 240, 176, 89, 400, 340, 10, 40, 54, 89, 340, 205), sex = c("F", "M")) ba<-ggplot(dt[dt$area=="BA",], mapping = aes(y = dmean, x = sex, color = sex, fill=sex))+ geom_violin(alpha=.5,scale = "width",trim = FALSE, position=position_dodge(1))+ ggtitle("Dive mean at BA and sex")+ scale_y_log10(breaks = c(10, 30, 50, 100, 200, 300, 400, 500)) + scale_fill_discrete(name="Social class", labels=c("Female", "Male"))+ xlab("Habitat")+ ylab("Dive depth (m)")+ theme_bw();ba mi<-ggplot(dt[dt$area=="MI",], mapping = aes(y = dmean, x = sex, color = sex, fill=sex))+ geom_violin(alpha=.5,scale = "width",trim = FALSE, position=position_dodge(1))+ ggtitle("Dive mean at MI and sex")+ scale_y_log10(breaks = c(10, 30, 50, 100, 200, 300, 400, 500)) + scale_fill_discrete(name="Social class", labels=c("Female", "Male"))+ xlab("Habitat")+ ylab("Dive depth (m)")+ theme_bw();mi fa<-ggplot(dt[dt$area=="FA",], mapping = aes(y = dmean, x = sex, color = sex, fill=sex))+ geom_violin(alpha=.5,scale = "width",trim = FALSE, position=position_dodge(1))+ ggtitle("Dive mean at FA and sex")+ scale_y_log10(breaks = c(10, 30, 50, 100, 200, 300, 400, 500)) + scale_fill_discrete(name="Social class", labels=c("Female", "Male"))+ xlab("Habitat")+ ylab("Dive depth (m)")+ theme_bw();fa t<-ggarrange(ba, mi, fa, ncol=3, nrow=1, common.legend = TRUE, legend="bottom");t #I tried insert: ggtitle = "Dive depths (m)" top = "Dive depths (m)") top=textGrob("Dive depths (m)"
Someone know how to do?