I'm trying to plot some temporal data that have some gaps in them. You can see the plot here: http://www.tiikoni.com/tis/view/?id=da222e2.
The problem is that during the time gaps in the TS the line plot is interpolated over the gap and I don't want it to. I've tried interleaving the gaps with an NA flag, but there are around 10000 datapoints sorted from multiple files, that makes it difficult to add the NA flag manually. If it's not possible to define the behaviour of the plot(0function, is there another plot I can use, e.g. zoo, that will allow me to not have the lines drawn between the gaps?
It's not difficult to interleave the gaps with NA using merge, once you know the sequence of your time series. A little demonstration :
X <- c(1:20,41:100)
Y <- rnorm(80)
plot(X,Y,type="l")
Z <- seq(min(X),max(X),by=1) # I take 1 is the period.
newData <- merge(data.frame(X,Y),data.frame(X=Z),all=T)
plot(newData,type="l")
Create a zoo series with a gap. Then define g
which includes the time points of z plus the missing points. Create a zero width zoo series to merge with z
and plot.
library(zoo)
z <- zoo(rnorm(12), c(1:6, 11:16)) # test data
g <- seq(start(z), end(z), 1)
zz <- merge(z, zoo(, g))
plot(zz)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With