[R] stacked histograms

Deepayan Sarkar deepayan.sarkar at gmail.com
Fri Apr 13 20:03:19 CEST 2007


On 4/13/07, Arne Schröder <arne.schroder at emg.umu.se> wrote:
> I want to produce stacked histograms where the total bar is divided up
> according to the n levels of the grouping variable given in the group
> argument.
> I am using the lattice histogram function and its "group"-argument, but
> it is not recognised. The "auto.key" argument, however, is, because it
> gives
> me the correct group levels and when setting groups = NULL, auto.key =
> TRUE is obviously not producing any legend). Is this because the default
> "panel"-argument of histogram() = panel.histogram has no group-argument
> (in contrast to the xyplot() function and xyplot.histogram)? Is tehre a
> way around it?

Write your own panel function, it shouldn't be too hard.

Don't expect it to be part of lattice, because I think stacked
histograms are a bad idea (use stacked bar charts for factors or
grouped density plots for continuous data) and it will not be in
lattice for the same reason there are no pie charts. Histograms are
bad enough to begin with.

-Deepayan



More information about the R-help mailing list