[R] geom_ribbon removes missing values
Hadley Wickham
hadley at rice.edu
Mon May 31 21:51:48 CEST 2010
Hi Karsten,
There's no easy way to do this because behind the scenes geom_ribbon
uses grid.polygon.
Hadley
On Sun, May 30, 2010 at 7:26 AM, Karsten Loesing
<karsten.loesing at gmx.net> wrote:
> Hi everyone,
>
> it looks like geom_ribbon removes missing values and plots a single
> ribbon over the whole interval of x values. However, I'd rather want it
> to act like geom_line, that is, interrupt the ribbon for the interval of
> missing values and continue once there are new values. Here's an example:
>
> library(ggplot2)
> df <- data.frame(
> date = seq(from = as.Date("2010-05-15"),
> to = as.Date("2010-05-24"),
> by = "1 day"),
> low = c(4, 5, 4, 5, NA, NA, 4, 5, 4, 5),
> mid = c(8, 9, 8, 9, NA, NA, 8, 9, 8, 9),
> high = c(12, 13, 12, 13, NA, NA, 12, 13, 12, 13))
> ggplot(df, aes(x = date, y = mid, ymin = low, ymax = high)) +
> geom_line() +
> geom_ribbon(fill = alpha("blue", 0.5))
>
> When running this code, R tells me:
>
> Warning message:
> Removed 2 rows containing missing values (geom_ribbon).
>
> When you look at the graph, you can see that the line stops at May 18
> and starts again on May 21. But the ribbon reaches from May 15 to 24,
> even though there are no values on May 19 and 20.
>
> Is there an option that I could set? Or a geom/stat that I should use
> instead? In my pre-ggplot2 times I used polygon(), but I figured there
> must be something better in ggplot2 (as there has always been so far).
>
> Thanks,
> --Karsten
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
More information about the R-help
mailing list