customizing a panel plot

3 views
Skip to first unread message

nick

unread,
Dec 6, 2010, 4:17:56 PM12/6/10
to ggplot2
Hi-

I came across the following link which gives an example that is very
similar to a graph which I am trying to create, stacking several time
series for comparison:
http://learnr.wordpress.com/2009/05/18/ggplot2-three-variable-time-series-panel-chart/

However, I cannot figure out how (or if it is possible) to, say, add a
rectangle geom onto one or all of the three plots in this single
figure. The goal is to highlight a specific interval of time. I have
tried inserting a single geom_rect() command in different places in
the code workflow, but do not understand the grammar well enough to
know how to do this. Can anyone suggest a method that could achieve
this goal?

Thanks much,
Nick

baptiste auguie

unread,
Dec 7, 2010, 1:39:45 AM12/7/10
to nick, ggplot2
Hi,

Try this,

library(ggplot2)
d = data.frame(x=rnorm(20), y = rnorm(20), f =
factor(rep(letters[1:2],each=10)))

dd = data.frame(f="b", xmin=-0.5, ymin=-Inf, xmax=0.5, ymax=Inf) # for
the rectangle, only in panel "b"


ggplot(d) + facet_grid(f~.) +
geom_rect(aes(xmin=xmin,ymin=ymin, xmax=xmax, ymax=ymax),
fill="red", alpha=0.2, data=dd) +
geom_point(aes(x,y))

HTH,

baptiste

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

Reply all
Reply to author
Forward
0 new messages