This is my data:
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)
And here is what I have so far:
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") ```
How can I either insert my legend information below the xaxis or make more clear which bars belong to which symptom by using a vertical line or anything?
I would be happy with ablines between the groups of symptoms. But if someone also has an idea of how to put the Study IDs below the xaxis vertical written that would be just great!!
Here is what I have tried:
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")
With that know one really can know which bar is for which Study. Second Version with Text but on the plot instead of below xaxis
