简体   繁体   English

堆叠条形图中的订单组按R中的总和

[英]Order groups in a stacked stripchart by sum in R

I have a grouped and stacked stripchart() in R . 我在R有一个分组和堆叠的stripchart()

stripchart(gear ~ cyl, data=mtcars, method="stack")

在此输入图像描述

cyl are the groups here. cyl是这里的团体。 I want to groups ordered by its sum. 我想要按其总和排序的团体。 From bottom to top the ordering should be 6, 4 and 8. 从下到上,排序应为6,4和8。

How can I do this automaticly in a stripchart ? 如何在stripchart自动执行此stripchart

As mentiont from Jota and with detailed help from How to order factors by condition in R? 正如Jota提到的那样,以及如何根据R中的条件订购因子的详细帮助

Transforming cyl into factor and order it's levels. cyl转换为factor并命令它的级别。

mtcars$cyl <- factor(mtcars$cyl, levels=names(sort(table(mtcars$cyl))))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM