Hi:
On Fri, Mar 22, 2013 at 3:59 PM, Stephanie May <
miz...@gmail.com> wrote:
> geom_ribbon() works when the x axis is numeric:
>
> data <- data.frame(TMAX = rnorm(10)+10,TMIN = rnorm(10) - 10, MDAY =
> rep(1:10))
> ggplot(data,aes(x=MDAY)) + geom_ribbon(aes(ymin=TMIN,ymax=TMAX))
>
> but not when the x axis is character:
> data <- data.frame(TMAX = rnorm(10)+10,TMIN = rnorm(10) - 10, MDAY =
> letters[1:10])
> ggplot(data,aes(x=MDAY)) + geom_ribbon(aes(ymin=TMIN,ymax=TMAX))
Firstly, by the way you defined your data frame, MDAY is not character:
> str(data)
'data.frame': 10 obs. of 3 variables:
$ TMAX: num 9.73 10.18 8.82 9.85 9.8 ...
$ TMIN: num -9.51 -9.75 -11.37 -8.7 -9.73 ...
$ MDAY: Factor w/ 10 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10
>
> Why???
geom_ribbon() is intended for continuous x. If you use geom_ribbon()
with a discrete x, are you not misleading the consumer of your graphic
into believing that the x-variable is continuous?
>
> Can anyone suggest a workaround?
Here are a couple, but they may not be what you want:
ggplot(data, aes(x = MDAY)) +
geom_segment(aes(xend = MDAY, y = TMIN, yend = TMAX), size = 1)
ggplot(data, aes(x = MDAY)) +
geom_pointrange(aes(y = (TMIN + TMAX)/2, ymin = TMIN, ymax =
TMAX), size = 1)
geom_pointrange() expects a 'middle point' - I chose the midrange of
TMIN and TMAX, but if you decide to use this and want a different
value, you'll need to include another variable in your data frame.
Dennis
>
> Thanks much!
> Stephanie
>
> --
> --
> 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.
>
>