根据中值对箱线图进行排序
我想使用 R 制作一系列按中值排序的箱线图。假设然后我执行:
boxplot(cost ~ type)
这会给我一些箱线图,成本显示在 y 轴上,类型类别在 x 轴上可见:
----- -----
| |
[ ] |
| [ ]
| |
----- -----
A B
但是,我想要的是从最高到最低中值排序的箱线图数字。我怀疑我需要做的是更改类型(A 或 B)的标签以数字方式指示哪个是最低和最高中值,但我想知道是否有更聪明的方法来解决该问题。
I'd like to use R to make a series of boxplots which are sorted by median value. Suppose then I execute:
boxplot(cost ~ type)
This would give me some boxplots were cost is shown on the y axis and the type category is visible on the x-axis:
----- -----
| |
[ ] |
| [ ]
| |
----- -----
A B
However, what I'd like is the boxplot figures sorted from highest to lowest median value. My suspicion is that what I need to do is change the labels of the type (A or B) to numerically indicate which is the lowest and highest median value, but I wonder if there is a more clever way to solve the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看
?重新排序
。该示例似乎是您想要的,但按相反的顺序排序。我更改了下面第一行中的-count
以按您想要的顺序排序。Check out
?reorder
. The example seems to be what you want, but sorted in the opposite order. I changed-count
in the first line below to sort in the order you want.是的,就是这个想法:
Yes, that is the idea:
请注意缺失值,您必须添加
na.rm = TRUE
才能正常工作。如果没有,该代码根本无法工作。我花了几个小时才发现这一点。Beware of missing values, you have to add
na.rm = TRUE
for it to work. If not, the code simply doesn't work. It took me hours to found that out.