I've got something like 20 facets on a geom_line
ggplot2
plot, with an overlaid geom_rect
based on timeseries data, all with a facet_wrap
. I constantly need to update my plots, and the order of my facets ultimately may need to change on a daily basis.
My question is: is it possible to order my facets using my time-series data in geom_rect
? I.e. make the first facet the one that has the first geom_rect
shaded area, and so on and so forth?
Here is my code: x-axis is date, y-axis is incidence3, and faceted by geo....
ggplot () +
geom_rect(data=total,
aes(xmin=as.Date(xmin),
xmax=as.Date(xmax),
ymin=-Inf,
ymax=Inf),
fill='light blue',
alpha=0.3) +
ylab("incidence") + xlab("time") +
facet_wrap(~geo) +
geom_line(data=total, aes(x=as.Date(date), y=incidence3)) +
facet_wrap(~geo, ncol=2, scale = "free_y")