color line segment with ggplot?

125 views
Skip to first unread message

Yasutaka Hirasawa

unread,
May 17, 2013, 4:10:38 PM5/17/13
to ggp...@googlegroups.com

Dennis Murphy

unread,
May 18, 2013, 4:53:05 AM5/18/13
to Yasutaka Hirasawa, ggplot2
Why, yes we can!!! (Sounds like an old campaign rally cry, but I digress...)

Instead of regex, I used rle() instead and did some playing around
with indices. It's a little tedious, but it seems to work. The basic
idea is to extract the subset of the series for which the index has
fallen from the previous quarter and do exactly the same thing with
the corresponding indices offset by 1 (so that we start at the top and
end at the bottom after we join the two data frames together). We then
create two ggplot layers: the first is of the entire series using
geom_path() and the second is of the subset of falling GDPs using
geom_segment() in a different color. I used the series from Rob
Hyndman's web site since the help page lied about the start and end of
the series :)

The entire code is attached as a file since it's a bit long for a
post. I'm sure it can be tidied up a bit.

Dennis



On Fri, May 17, 2013 at 1:10 PM, Yasutaka Hirasawa <dank...@gmail.com> wrote:
> wonder if we can generate the same chart using ggplot2?
> http://www.r-bloggers.com/finding-patterns-in-time-series-using-regular-expressions/
>
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
bicolorLine.R
Reply all
Reply to author
Forward
0 new messages