The following works, giving 3 points connected with a line.
plot(c(1,7,12), c(0,0,2),type="b")
However this does not work (it plots the points but without connecting line and without any warning or error)
t<-data.frame(x=1:20,y=c(0,NA, NA, NA, NA, NA, 0, NA, NA, NA, NA, 2, NA, NA, NA, NA, NA, NA, NA, NA))
plot(t$x, t$y,type="b")
Why is that? Is it because of the NA in the data frame? I can’t seem to find any reference on this.
That is the intended, documented, and (when you need to plot lines with breaks in them) desirable behavior of R’s
lines()function. From the?lineshelp page:To get lines between the points, simply remove the points for which
yhas a value ofNA: