[R] problem with abline for x.y

Michael Friendly friendly at yorku.ca
Fri Feb 20 15:17:37 CET 2004

I'm trying to do a sunflowerplot of Galton's data, with both regression 
lines and data ellipses,
and I must be doing something wrong, because the lines do not intersect 
at \bar{x}, \bar{y}.
The problem is likely in the line for x.y, but I don't know how to 
specify that correctly.

The data is read in grouped form( galton), and then ungrouped (galton2):

galton <- read.table("~/sasuser/data/galton.txt", header=TRUE)
# ungroup
galton2<-galton[rep(1:nrow(galton), galton$frequency), 1:2]

sunflowerplot(child, parent, number=frequency, xlim=c(61,75), 
    xlab="Child height", ylab="Mid Parent height")

# both attempts plot the same, wrong regression lines
y.x <- lm(parent ~ child, weights=frequency)
x.y <- lm(child ~ parent, weights=frequency)
abline(x.y, col="gray")

y.x <- lm(parent ~ child)
abline(y.x, lwd=2)
x.y <- lm(child ~ parent)
abline(x.y, col="gray", lwd=2)

data.ellipse(child, parent, plot.points=FALSE, levels=c(0.40, 0.68), lty=2)

The resulting figure may be seen at


Michael Friendly     Email: friendly at yorku.ca 
Professor, Psychology Dept.
York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street    http://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT  M3J 1P3 CANADA

More information about the R-help mailing list