I am trying to plot two time-series data with ggplot2, and add a break on purpose between two years. Here is the example code:
library(ggplot2)
library(xts)
ny=3
n = 365*ny
md = data.frame('Date' = as.Date('2001-01-01') + 1:n -1,
'P' = rep(sin(seq(0, pi/2, length.out=365)), ny),
'ET' = rep(sin(seq(0, pi/2, length.out=365)), ny)*0.8 )
mf = reshape2::melt(md, id='Date')
mf=cbind(mf, 'year' = as.numeric(substr(mf$Date, 1, 4)))
ggplot(data=mf)+
geom_line(aes(x=Date, y=value, color=variable, grouping=year))
The line for ET and P are continuous at 12-31 to 01-1 of next year. How to make a gap between them? Thank you.
