[R] ggplot2 stacked line plot

Liam Blanckenberg liam.blanckenberg at gmail.com
Mon Feb 8 05:40:25 CET 2010

Hi all,

I have been hunting around for hours trying to figure out how to
generate a stacked line chart using ggplot2. This type of chart can be
generated in excel 2007 by selecting: Chart type > Line > Stacked
line. I can generate a stacked area chart using the following code:

   p <- ggplot2(~, aes(x = ~, y = ~, colour = Type)) +
geom_area(aes(position = 'stack', fill = Type))

However, when I try and replicate this using the following code for geom_line:

   p <- ggplot(~, aes(x = ~, y = ~, colour = Type)) +
geom_line(aes(position = 'stack'))

the resulting plot is not stacked - i.e. each 'Type' is plotted at its
actual value rather than cumulatively to form a stacked chart... I
have poured through Hadley's ggplot2 book (ggplot2: elegant graphics
for data analysis), the R help list and also done general google
searching but cannot find a way to generate this type of plot.

R version: 2.9.2
ggplot2 version: 0.8.5
OS: windows 7 (64-bit).

Any suggestions or assistance would be greatly appreciated.



More information about the R-help mailing list