0

I would like to create a horizontal proportional stacked bar "chart", using R.

My data is unidimensional. It represents failure rates in successive categories, and looks like this:

taskC=c(16, 10, 13, 5, 4, 5, 12)
labels=c("All correct", "1 fail", "2 fails", "3 fails", "4 fails", "5 fails", "All fail")

I would like to create something along the lines of the chart at the below URL, though using a different colour graident (topo is fine) and having it horizontal instead of vertical.

http://www.improving-visualisation.org/vis/id=70

I've looked through ggplot and VCD and can't find anything that solves this. A 3d graph would be ideal, though not critical. Although the data can be represented using a pie chart, these don't provide the linear sense of proportion I want, and also don't sufficiently capture the ordinal nature of the data.

Leon Derczynski
  • 542
  • 5
  • 15
  • [Possible duplicate](http://stackoverflow.com/questions/7583432/plot-stacked-bar-plot-in-r)? Horizontal stacked plots are covered on [the ggplot2 help page for bar plots](http://had.co.nz/ggplot2/geom_bar.html), by the way. – Matt Parker Jan 19 '12 at 18:05
  • 1
    Also, if you're concerned enough about perception to want to use linear rather than angular representations of your data, you should probably skip the 3D stuff - it doesn't add anything when you're presenting 1D data. – Matt Parker Jan 19 '12 at 18:07
  • 2
    Another possible duplicate: http://stackoverflow.com/questions/8872428/ggplot-stacked-bar-plot-how-to-apply-different-length-color-ramps-to-each-bar/8874378#8874378 – John Colby Jan 19 '12 at 18:07
  • The dupe candidates don't work as well for cumulative representations; thanks for the tip about 3d, in retrospect, I quite agree – Leon Derczynski Jan 19 '12 at 19:18

1 Answers1

1

You can simply do:

barplot(as.matrix(taskC), horiz=TRUE, col=rainbow(7), xaxt="n")
axis(1, labels=labels, at=cumsum(taskC)-(taskC/2))
nico
  • 50,859
  • 17
  • 87
  • 112