问题
I have a grouped and stacked stripchart()
in R
.
stripchart(gear ~ cyl, data=mtcars, method="stack")
cyl
are the groups here. I want to groups ordered by its sum. From bottom to top the ordering should be 6, 4 and 8.
How can I do this automaticly in a stripchart
?
回答1:
As mentiont from Jota and with detailed help from How to order factors by condition in R?
Transforming cyl
into factor
and order it's levels.
mtcars$cyl <- factor(mtcars$cyl, levels=names(sort(table(mtcars$cyl))))
来源:https://stackoverflow.com/questions/42426970/order-groups-in-a-stacked-stripchart-by-sum-in-r