[R] ggplot2 stacked line plot

hadley wickham h.wickham at gmail.com
Tue Feb 9 15:53:27 CET 2010


Hi Liam,

Your syntax is a little off.  You want:

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

Position isn't an aesthetic.

Hadley

On Sun, Feb 7, 2010 at 10:40 PM, Liam Blanckenberg
<liam.blanckenberg at gmail.com> wrote:
> 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.
>
> Regards,
>
> Liam
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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



More information about the R-help mailing list