【发布时间】:2020-11-21 00:33:47
【问题描述】:
这是我的数据:
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 下方插入我的图例信息,或者通过使用垂直线或其他任何东西更清楚哪些条属于哪个症状?
我会很高兴看到症状组之间的 ablines。但是,如果有人也知道如何将研究 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")
有了这个知识,人们就可以真正知道哪个酒吧是哪个 Study。 Second Version with Text but on the plot instead of below xaxis
【问题讨论】: