Legend ordering in ggplot2

旧城冷巷雨未停 提交于 2019-12-04 17:32:06

It's changing names into a factor variable and using alphabetical order by default

use

df$names <- factor(df$names, levels = c("1 year","4 years","15 years","25 years","40 years"))

You could use fct_inorder from the forcats package to turn the names vector into an ordered factor in your desired "1 year, 4 years", etc sequence:

library(forcats)
names = fct_inorder(c(names1,names2,names3,names4,names5))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!