在 R 中任意重新排序直方图列
我想知道如何以对我的数据有意义的方式重新排序直方图的列。这个例子说明了我正在尝试做的事情。
我在一个文件中有这些数据:
blue low
blue medium
blue high
blue high
blue high
blue medium
green low
green low
green low
green high
pink low
pink high
pink medium
pink low
pink high
red high
red low
red low
red low
red medium
red medium
red medium
如果我运行这些命令:
colours <- read.table("colours.txt", sep="\t")
library(lattice)
histogram(~ V2 | V1, data=colours, type="count")
我得到了几乎我想要的东西,除了直方图中的列按字母顺序排序,高,低,中和 我想让它们以更自然的方式排序为低、中、高。
预先非常感谢您提供有关如何实现此目标的任何指示。
I would like to know how I can re-order the columns of a histogram in a way that makes sense to my data. This example illustrates what I'm trying to do.
I have this data in a file:
blue low
blue medium
blue high
blue high
blue high
blue medium
green low
green low
green low
green high
pink low
pink high
pink medium
pink low
pink high
red high
red low
red low
red low
red medium
red medium
red medium
If I run these commands:
colours <- read.table("colours.txt", sep="\t")
library(lattice)
histogram(~ V2 | V1, data=colours, type="count")
I get pretty much what I want except that the columns in the histograms are sorted alphabetically, high, low, medium and
I would like to have them sorted in the more natural way low, medium, high.
Thanks very much in advance for any pointers on how to accomplish this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需要订购您的因素:
You just need to order your factors: