[R] Stacked Area Plot

hadley wickham h.wickham at gmail.com
Wed Sep 17 20:17:50 CEST 2008


On Wed, Sep 17, 2008 at 1:01 PM, Josip Dasovic <jjd9 at sfu.ca> wrote:
> Hi:
>
> I've searched the archives and the Internet for hours but have yet to find a way to do stacked area plots (like the kind in Excel) in R.  I think that polygon may work but it would require a bit of manipulation of my data. I was hoping for an easier way.
>
> An example of what I'm trying to do can be found here:
> http://jcharts.sourceforge.net/samples/stackedArea.html

These are pretty easy in ggplot2:

df <- data.frame(
  trt = rep(letters[1:3], each = 10),
  year =  rep(1:10, 3),
  value = abs(rnorm(30))
)

install.packages("ggplot2")
library(ggplot2)
qplot(year, value, data=df, geom="area", fill = trt)

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



More information about the R-help mailing list