[Rd] plot.lm: "Cook's distance" label can overplot point labels

From: John Maindonald <john.maindonald_at_anu.edu.au>
Date: Wed, 18 Feb 2009 09:53:39 +1100


The following code demonstrates an annoyance with plot.lm():

library(DAAGxtras)
x11(width=3.75, height=4)
nihills.lm <- lm(log(time) ~ log(dist) + log(climb), data = nihills) plot(nihills.lm, which=5)

OR try the following
xy <- data.frame(x=c(3,1:5), y=c(-2, 1:5)) plot(lm(y ~ x, data=xy), which=5)

The "Cook's distance" text overplots the label for the point with the smallest residual. This is an issue when the size of the plot is much less than the default, and the pointsize is not reduced proportionately.

I suggest the following:

       xx <- hii
       xx[xx >= 1] <- NA

## Insert new code
fracht <- (1.25*par()$cin[2])/par()$pin[2] ylim[1] <- ylim[1] - diff(ylim)*max(0, fracht-0.04)
## End insert new code
plot(xx, rsp, xlim = c(0, max(xx, na.rm = TRUE)), ylim = ylim, main = main, xlab = "Leverage", ylab = ylab5, type = "n", ...) Then, about 15 lines further down, replace legend("bottomleft", legend = "Cook's distance", lty = 2, col = 2, bty = "n") by legend("bottomleft", legend = "Cook's distance", lty = 2, col = 2, bty = "n", y.intersp=0.5)

If this second change is not made, then one wants fracht <- (1.5*par() $cin[2])/par()$pin[2]
I prefer the "Cook's distance" text to be a bit closer to the x-axis, as it separates it more clearly from any point labels.

John Maindonald email: john.maindonald_at_anu.edu.au phone : +61 2 (6125)3473 fax : +61 2(6125)5549 Centre for Mathematics & Its Applications, Room 1194, John Dedman Mathematical Sciences Building (Building 27) Australian National University, Canberra ACT 0200.



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 17 Feb 2009 - 21:56:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 18 Feb 2009 - 04:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive