如何解决添加主标题多个情节ggarange
我有一个数据框 dt
,其中包含有关潜水行为和三个不同区域 BA,MI,FA
的数据。
我想使用 ba,mi,fa
将主标题添加到我的多个图 (ggarrange
),但我没有找到有用的东西。
我想在我的 3 个图的顶部添加主标题“潜水深度(米)”
library(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,40,54,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,100,300,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",position=position_dodge(1))+
ggtitle("Dive mean at MI and sex")+
scale_y_log10(breaks = c(10,"Male"))+
xlab("Habitat")+
ylab("Dive depth (m)")+
theme_bw();mi
fa<-ggplot(dt[dt$area=="FA",position=position_dodge(1))+
ggtitle("Dive mean at FA and sex")+
scale_y_log10(breaks = c(10,"Male"))+
xlab("Habitat")+
ylab("Dive depth (m)")+
theme_bw();fa
t<-ggarrange(ba,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)"
有人知道怎么做吗?
解决方法
您可以使用 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))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。