[R] Grouped AND stacked bar charts possible in R?
lenon at fstrf-wi.org
Tue Jun 22 17:54:58 CEST 2004
Good day all,
My statisticians want an R procedure that will produce grouped stacked
barplots. Barplot will
stack or group, but not both. The ftable function can produce a table
of the exact form they want, but the barplot doesn't show all the
divisions we want.
For an example, here's the sample from the help file for "ftable:"
ftable(Titanic, row.vars = 1:3)
ftable(Titanic, row.vars = 1:2, col.vars = "Survived")
ftable(Titanic, row.vars = 2:1, col.vars = "Survived")
Now take it a step further to try to add another dimension:
b <- ftable(Titanic, row.vars=1:3)
Survived No Yes
Class Sex Age
1st Male Child 0 5
Adult 118 57
Female Child 0 1
Adult 4 140
2nd Male Child 0 11
Adult 154 14
Female Child 0 13
Adult 13 80
3rd Male Child 35 13
Adult 387 75
Female Child 17 14
Adult 89 76
Crew Male Child 0 0
Adult 670 192
Female Child 0 0
Adult 3 20
Neither resulting barplot is satisfactory. The first stacks all the
subdivisions of "Survived = Yes" and "Survived = No" together. The
second is closer because it creates two groups, but it lists
combinations side-by-side that we'd like stacked. In the above example
"No" and "Yes" would be stacked on bars labeled "Male" or "Female"
in groups by Class.
I've taken a look through the R-Help archives and looked through the
contributed packages, but haven't found anything yet.
If you have any thoughts how we might produce groups of stacked bars
from an ftable, we would appreciate it.
More information about the R-help