重新排序()不正确地重新排序ggplot中的一个因子变量 [英] Reorder() not correctly reordering a factor variable in ggplot

查看:125
本文介绍了重新排序()不正确地重新排序ggplot中的一个因子变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  set.seed(200)$我很困惑为什么这些箱子不会在这个图上订购:

b $ bx < - data.frame(country = c(rep('UK',10),
rep(USA,10),
rep(Ireland,5)),
wing = c(rnorm(25)))

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



如何根据最高的最低中位数(从左到右)排序箱型图?

解决方案

因为你没有使它成为一个有序的因素。尝试

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


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("USA", 10), 
                          rep("Ireland", 5)),
                wing=c(rnorm(25)))

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

How can I order the boxplots based on highest-lowest medians (left to right)?

解决方案

Because you did not make it an ordered factor. Try

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

这篇关于重新排序()不正确地重新排序ggplot中的一个因子变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆