Contour Plot Breaks Off?

Today I experimented with the good old contour plots in R. I plotted my points rather large, because there is quite some uncertainty around their precise placement. In this particular case, I start with an empty plot and a custom range, and add the points separately. Note the cex=8 to draw extra large points.

plot(c(80, 740), c(180, 740) , type='n', xlab="", ylab="", bty="n", main="")
points(jitter(x), jitter(y), cex=8, pch=19, col="#AA449950")

Then I added contours, and they were cut off, breaking off where I expected them to go around the dots. Why are there incomplete lines at the top and bottom?

It turns out — a.k.a. read the manual — that kde2d sets the default limits to the range (I guess this is quite reasonable in other cases): lims = c(range(x), range(y)). Now my big dots obviously cover more than the strict range of values, so all I needed to do was set my own lims in kde2d.

Here’s the entire code for the plot:
plot(c(80, 740), c(180, 740) , type='n', xlab="", ylab="", bty="n", main="")
points(jitter(x), jitter(y), cex=8, pch=19, col="#AA449950")
library(MASS)
# z = kde2d(x, y, n=50) # this one didn't work out
z = kde2d(x, y, n=50, lims=c(80, 740, 180, 740))
contour(z, drawlabels=FALSE, nlevels=6, col="#AA4499", add=TRUE)

A search engine for R

With the increasing popularity of R, using a common search engine like Google has become more viable. Yes, single-letter searching may be cool, but it’s much more difficult to restrict results. While Google has become better in producing relevant results when the single letter R is added, there’s one search engine that still works better: Rseek. Using customized Google searches, Rseek is much less likely than an ordinary Google search to produce results that are about STATA or SAS, for instance (less helpful if we’re looking for relevant code). Rseek even provides separate results for packages, books, support, beginners, and articles.