1

I tried this question on the R-Help list with no success CrossPostHere...

I am working on some xyplots using the Lattice Library. My X-axis is the date and I am reproducing charts similar to those found in the R Gallery (see here:R-Gallery Trellis)

However, the key difference is that some of my data is missing (not collected at that time). For instance, I might have a whole month that I do not have data. The problem is that xyplot connects the data points.

To continue with the R Gallery plot example, if your Outside Temperature data stopped at 20 degrees in March 2007 and picked back up in July 2007 at 20 degrees you would have a straight line connecting the two data points (at 20 degrees). I would rather have no line which would (in my opinion) better represent that no data was collected for that time period.

I am curious to know if anyone has a idea of how to alter this behavior so that the lines are not connected when data are missing in the series. I am hoping there is an easy or slick solution but as I started to think about it, it might be rather complex because you'd need to tell xyplot what granularity you'd like to not connect (e.g. 5 hours in a row, 4 days in a row, etc).

Any help would be much appreciated !

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user918967
  • 2,049
  • 4
  • 28
  • 43
  • If you are cross-posting elsewhere, it is a good idea to link to the question you asked elsewhere. Also, it's easiest to help you if you [provide a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Michael Hoffman Nov 17 '11 at 05:57

1 Answers1

4

Put NA where you have missing data, and xyplot() shouldn't connect it. This works for me on R 2.13.2:

d <- data.frame(x = 1:10, y = 1:10)
d[5,"y"] = NA
xyplot(y ~ x, d, type = "b")
Michael Hoffman
  • 32,526
  • 7
  • 64
  • 86