The issue is that coord_polar isn't really polar; it's more like a
warping of the rectangular space into a circular one. Because of this,
the values don't "wrap around" from negative to positive values.
If you want to plot things that cross over theta=0, then you'll have
to fake it by using two separate pieces, as you described in your
workaround. (Or you could change the origin angle and use labels with
fake values for the theta breaks.)
-Winston
On Tue, Dec 11, 2012 at 4:31 AM, Marcin <
mwlod...@gmail.com> wrote:
>
> Hi,
>
> I'm trying to use geom_rect with coord_polar to plot circular range (the
> shortest arc containing all the data points) like this:
>
> df = data.frame(angle=c(6,1), length=c(.6,.5))
>
> base <- ggplot(df, aes(x=angle, y=length))
> base + coord_polar(start=pi/2, direction=1) +
> geom_rect(aes(ymin=0, ymax=1, xmin=6, xmax=1), fill = colors()[230],
> alpha=0.3) +
> geom_segment(aes(y=0, xend=angle, yend=length), size=1) +
> scale_x_continuous(
> breaks=c(0, pi/2, pi, (3 * pi) /2),
> limits=c(0, 2*pi),
> labels=c('0', expression(pi / 2), expression(pi), expression(3 * pi / 2)))
> +
> ylim(0, 1)
>
> Everything is fine as long as long as geom_rect doesn't need to go across
> zero (as is the case in the example above). Swapping xmin and xmax doesn't
> make any difference.
>
> I can of course work around it by plotting to rectangles: one from xmin to 2
> * pi and another from 0 to xmax but I was wondering whether there is a
> better way of doing this.
>
> Thanks!
> Marcin
>
> --
> 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