ggplot: how to specify vertical order of multiple boxplots?

前端 未结 1 1899
醉梦人生
醉梦人生 2021-01-13 07:01

I would like to change the stacking order of hospitals in the diagram below so #1 is at the top and #4 at the bottom.

The diagram was produced with

         


        
相关标签:
1条回答
  • 2021-01-13 07:34

    You have a few options. The easiest would be to add

    p + scale_x_reverse()
    

    to the plot. You could also reverse the levels of the factor

    relevel(survey$hospital, rev(levels(survey$hospital))) -> survey$hospital
    

    Or, you could determine the order you want the boxes by hand with xlim()

    p + xlim("Hospital #4","Hospital #3","Hospital #2","Hospital #1")
    
    0 讨论(0)
提交回复
热议问题