[R] Stacked Area Plot

hadley wickham
Wed, 17 Sep 2008 18:17:50 -0000

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
--