gpt4 book ai didi

r - 添加主标题多个情节ggarange

转载 作者:行者123 更新时间:2023-12-04 12:09:43 24 4
gpt4 key购买 nike

我有一个数据框 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, 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)"

有人知道怎么办吗?

最佳答案

您可以使用 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))
enter image description here

关于r - 添加主标题多个情节ggarange,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65694397/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com