Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想更改下图中医院的堆叠顺序,使#1 在顶部,#4 在底部。
该图是用
ggplot(survey,aes(x=hospital, y=age))+geom_boxplot()+coord_flip()+xlab("")+ylab ("\nPatient Age")
我需要自上而下的顺序与现在相反。我不知道为什么会变成现在这样。“医院”一栏是一个重要因素。
非常感谢!
你有几个选择。最简单的方法是添加
p + scale_x_reverse()
到情节。您还可以反转因子的水平
relevel(survey$hospital, rev(levels(survey$hospital))) -> survey$hospital
或者,您可以手动确定您想要的盒子的顺序xlim()
xlim()
p + xlim("Hospital #4","Hospital #3","Hospital #2","Hospital #1")