I have the following code (as an example) that I would like to adapt in such a way that the tape spreads to the whole xrange, as it does geom_hline(). The tape indicates which values are within acceptable limits. In my real application, sometimes there is no upper or lower bound, so the hline itself is not enough to determine if the values are within the bounds.
library(ggplot2)
set.seed(2016-12-19)
dates <- seq(as.Date('2016-01-01'), as.Date('2016-12-31'), by = 1)
values <- rexp(length(dates), 1)
groups <- rpois(length(dates), 5)
temp <- data.frame(
date = dates,
value = values,
group = groups,
value.min = 0,
value.max = 2
)
ggplot(temp, aes(date, value)) +
geom_ribbon(aes(ymin = value.min, ymax = value.max), fill = '#00cc33', alpha = 0.6) +
geom_hline(aes(yintercept = value.min)) +
geom_hline(aes(yintercept = value.max)) +
geom_point() +
facet_wrap(~group)
I tried to set xto geom_ribbonon dates, but then only a fraction of the range is filled. Also I tried this:
geom_ribbon(aes(ymin = -Inf, ymax = 2, x = dates), data = data.frame(), fill = '#00cc33', alpha = 0.6)
but then the data is likely to be overwritten for the entire graph, and I get an error Error in eval(expr, envir, enclos) : object 'value' not found. Even if this works, the range is still actually too narrow as the xlimits expand.