Reorder() not correctly reordering a factor variable in ggplot

前端 未结 3 1372
挽巷
挽巷 2021-01-01 19:30

I\'m baffled as to why the boxplots are not ordering in this plot:

set.seed(200)
x <- data.frame(country=c(rep(\'UK\', 10), 
                          rep         


        
3条回答
  •  猫巷女王i
    2021-01-01 20:18

    Because you did not make it an ordered factor. Try

    ggplot(x, aes(reorder(country, wing, median, order=TRUE), wing)) + geom_boxplot()
    

    enter image description here

提交回复
热议问题