Ggplot2 ggplot:如何将我的图例信息放在xaxis下面?

Ggplot2 ggplot:如何将我的图例信息放在xaxis下面?,ggplot2,geom-bar,Ggplot2,Geom Bar,这是我的数据: data_g <- data.frame( study_ID = c("ben-amitay2006","ben-ari2018", "ben-ari2019a","ben-ari2019b","connolly2004","lopez2008","phelan2009","toren2007","be

这是我的数据:

data_g <- data.frame(
  study_ID = c("ben-amitay2006","ben-ari2018", "ben-ari2019a","ben-ari2019b","connolly2004","lopez2008","phelan2009","toren2007","ben-amitay2006","ben-ari2019b","connolly2004","ben-amitay2006",
               "demaso2014","toren2007","ben-amitay2006","demaso2014","toren2007","demaso2014","ben-ari2018","ben-ari2019a","ben-ari2019b","kubota2011","sarrechia2015","ben-ari2018","ben-ari2019a",
               "sarrechia2015"),
  symptom = c("PTSD","PTSD","PTSD","PTSD","PTSD","PTSD","PTSD","PTSD",
              "Subthreshold PTSD","Subthreshold PTSD","Subthreshold PTSD","Depressive Symptoms",
              "Depressive Symptoms","Depressive Symptoms","Anxiety Sympomts","Anxiety Sympomts","Anxiety Sympomts",
              "Disruptive Behavior Sympomts","CBCL Clinical Range","CBCL Clinical Range","CBCL Clinical Range",
              "CBCL Clinical Range","CBCL Clinical Range","CBCL Borderline Range","CBCL Borderline Range","CBCL Borderline Range"),
  prevalence = c(0,10.39, 33.3, 10.2, 12, 0,0,29.03,7.7,26.4, 12,5, 4,18.52,12.5, 5,16.13,
                 16, 11, 30, 27.3, 45, 8.1,4,26.7, 3.9)
)

data_g$symptom <- factor(data_g$symptom, levels = c('PTSD', 'Subthreshold PTSD', 'Depressive Symptoms', 'Anxiety Sympomts', 'Disruptive Behavior Sympomts', 'CBCL Clinical Range', 'CBCL Borderline Range'))

library(RColorBrewer)
ggplot(data_g, aes(symptom, prevalence, fill = study_ID, label = study_ID)) + 
  geom_bar(stat="identity", position = position_dodge(preserve = 'single')) +
  scale_fill_brewer(palette = "Paired") +
  labs(x = "", fill = "Study ID") +
  ylim(0, 100) +
  theme(text = element_text(size=15)) +
  scale_x_discrete(guide = guide_axis(n.dodge = 2))+
  labs(title="Prevalence Rates of Psychological Symptoms after Surgery across Studies", x = "Psychological Symptoms", y = "Prevalence Rates in Percentage") ```

如何在xaxis下方插入图例信息,或通过使用垂直线或其他方式更清楚地说明哪些条属于哪个症状

我会很高兴看到两组症状之间的差异。但是如果有人也知道如何将研究ID放在xaxis垂直线下方,那就太好了

以下是我尝试过的:

ggplot(data_g, aes(symptom, prevalence, fill = study_ID, label = study_ID)) + 
  geom_bar(stat="identity", position = position_dodge(preserve = 'single')) +
  scale_fill_brewer(palette = "Paired") +
  labs(x = "", fill = "Study ID") +
  ylim(0, 100) +
  theme(text = element_text(size=15)) +
  scale_x_discrete(guide = guide_axis(n.dodge = 2))+
  geom_text(position = position_dodge(width = 1), aes(x=symptom, y=0), angle = 90, vjust=0, hjust = -0.06, size=2.5) +
  theme(legend.position = "none") +
  labs(title="Prevalence Rates of Psychological Symptoms after Surgery across Studies", x = "Psychological Symptoms", y = "Prevalence Rates in Percentage")
有了这些知识,你就可以真正知道哪个酒吧适合哪个研究。
实现这一点的一种方法是使用方面。而不是逐个症状在x轴面上绘制症状,并在x轴上绘制研究ID。试试这个:

数据