I have measurements of water quality in an irregular spaced time series (taken usually every month but not exactly on the same day every month). I've plotted these in the amazing ggplot with the code below, connecting all the measurements with a line.
However, there are also gaps, when no measurements are taken for several months. I would like to plot the lines between these points with another line type or color (say for example dotted and gray if the gap is larger than 60 days). Do i need to split my data for this? How do i approach this?
library(ggplot2)
library(lubridate)
xdate <- as.Date(c(seq.POSIXt(ymd("2005-01-01"), ymd("2007-03-04"), by = "30 days"),
seq.POSIXt(ymd("2007-07-03"), ymd("2007-12-31"), by = "28 days"),
seq.POSIXt(ymd("2008-05-15"), ymd("2010-10-10"), by = "25 days"),
seq.POSIXt(ymd("2012-01-01"), ymd("2014-12-31"), by = "31 days")))
set.seed(321)
df <- data.frame(date = rep(xdate,3), par=rep(c("Cl","PO4","NO3")), y=rnorm(318,1,0.2))
ggplot(df, aes(x=date, y=y)) +
geom_point(size=2) +
geom_line() +
facet_wrap(~par, nrow=3)