1

I have a grouped and stacked stripchart() in R.

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

enter image description here

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?

Community
  • 1
  • 1
buhtz
  • 10,774
  • 18
  • 76
  • 149
  • Have you tried making `cyl` a factor with the order of the levels determined by the group sum? – Jota Feb 23 '17 at 22:58
  • @Jota Sounds intereseting and R-like. But I don't know how to order factors by any condition (e.g. `sum`). – buhtz Feb 24 '17 at 21:09

1 Answers1

0

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))))
Community
  • 1
  • 1
buhtz
  • 10,774
  • 18
  • 76
  • 149