我很困惑为什么箱线图在此图中没有排序:
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()
如何根据最高-最低中位数(从左到右)对箱线图进行排序?
最佳答案
因为你没有将其设为有序因子。尝试一下
ggplot(x, aes(reorder(country, wing, median, order=TRUE), wing)) + geom_boxplot()
关于Reorder() 未正确重新排序 ggplot 中的因子变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16622979/