1
votes

I'm trying to accomplish something that I used to do in Excel, I have several timeseries for the same time interval and would like to plot them as lines (easy enough using ggplot geom_line), but one of them should be plotted as an area plot.

Basically something like this:

Desired

Plase note that the series S_1 is plotted as area.

I have already tried adding geom_area() with aes values equal to the value of the area series:

ggplot(df.lines, aes(x=Index, y=Value, colour=Series)) + geom_line() + geom_area(aes(x=df.area$Index, y=df.area$S_1))

How could I acomplish something like this using ggplot2?

1
How about trying: geom_area(data = df.area, aes(x=Index, y=S_1)). Also what have you tried, and what was the result?Mike H.
It just gave an error about Series object not found.pablete

1 Answers

2
votes

Difficult to test with no dataset (can you provide one on the example, you can use dput()), but in geom_area, the selection should be made in the data argument.. like this for instance..

ggplot +
geom_area(data = df.area[df.area$Series == "S_1", ], aes(x=Index, y=Value)) 
  geom_line(data = df.lines, aes(x=Index, y=Value, colour=Series))