[R] R Stacked Histogram

hadley wickham h.wickham at gmail.com
Sat Jan 3 16:16:22 CET 2009


On Fri, Jan 2, 2009 at 11:00 PM, Jason Rupert <jasonkrupert at yahoo.com> wrote:
> I've seen this asked, but never fully answered.
>
> Is it possible to plot stacked histograms in R?
>
> I have four data sets that I would like to show combined vertically in histogram format.
>
> Is this possible?

Yes, but it's generally not a terribly good way to display your data,
as it is hard to read the values of all except the series on the
bottom.

install.packages("ggplot2")
library(ggplot2)
qplot(carat, data = diamonds, binwidth = 0.1)
qplot(carat, data = diamonds, binwidth = 0.1, fill = cut)
qplot(carat, data = diamonds, binwidth = 0.1, fill = color)
qplot(carat, data = diamonds, binwidth = 0.1, fill = clarity)

More examples at http://had.co.nz/ggplot2/geom_histogram.html

Hadley


-- 
http://had.co.nz/




More information about the R-help mailing list