本文介绍了R - 因子水平的订单(和ggplot组轴顺序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我试图控制ggplot中轴上离散组的顺序,所以我设置了我的因子变量的顺序。使用levels()函数实际上似乎改变了数据框中的数据 - 而不是R处理数据的基础排序的方式(见下文)。难道我做错了什么?我应该使用哪个函数而不是levels()?谢谢! 尝试 pctCStack $ BRK 以下是参考资料: http://www.stat。 berkeley.edu/~s133/factors.html I am trying to control the order of discrete groups on an axis in ggplot, so I am setting the order of my factor variable. Using the levels() function actually seems to change the data in the data frame - not the way R treats the underlying ordering of the data (see below). Am I doing something wrong? which function should I use instead of levels()? thanks!head(pctCStack,4) BRK Time x1 ICs December 2013 0.67173002 Managers December 2013 0.80243443 ICs July 2014 2.04178514 Managers July 2014 1.3047233levels(pctCStack$BRK) <- c("0-2 Years", "2-4 Years", "4+ Years", "ICs", "Managers")head(pctCStack,4) BRK Time x1 0-2 Years December 2013 0.67173002 2-4 Years December 2013 0.80243443 0-2 Years July 2014 2.04178514 2-4 Years July 2014 1.3047233 解决方案 Try pctCStack$BRK <- factor(pctCStack$BRK, levels = c("0-2 Years", "2-4 Years", "4+ Years", "ICs", "Managers"))Here's a reference: http://www.stat.berkeley.edu/~s133/factors.html 这篇关于R - 因子水平的订单(和ggplot组轴顺序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-15 22:14