[R] ggplot2 stacked line plot
liam.blanckenberg at gmail.com
Tue Feb 9 23:21:25 CET 2010
Thanks for the pointing that error out to me. Unfortunately, revising
my code to:
p <- ggplot2(~, aes(x = ~, y = ~, colour = Type)) +
geom_line(aes(colour = Type), position = 'stack')
still does not generate what I'm after. I'm essentially after a line
plot where each 'Type' ('series' in excel lingo) is stacked in an
analogous fashion to a stacked area chart (i.e. geom_area(aes(Fill =
Type), position = 'stack')) - again using lines rather than areas
This chart should look just like a stacked area chart, however rather
than each 'layer' (representing a given 'Type') being filled with a
colour, each layer should have just a coloured line representing its
values. Summing each line vertically for a given value on the x-axis
across all the layers (i.e. 'Types') should then give the total y
value for that x value (just like vertically summing an area chart).
Really all I'm after is a stacked area chart where the fill for each
'Type' has been removed, leaving only a line for each (stacked) Type's
I hope this is somewhat clear!
On Wed, Feb 10, 2010 at 1:53 AM, hadley wickham <h.wickham at gmail.com> wrote:
> 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.
> 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.
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help