9

The code snippet below creates bivariate normal data, plots it and then plots an ellipse along with the line y=x

require(ellipse); require(MASS)

mu    <- c(30,30)
Sigma <- matrix(c(900,630,630,900),2,2,byrow=TRUE)
dt    <- data.frame(mvrnorm(n=1000,mu,Sigma))
names(dt) <- c("x","y")


plot(dt$x,dt$y)

df_ell <- data.frame(ellipse(cor(dt$x, dt$y), scale=c(sd(dt$x),sd(dt$y)), centre=c(mean(dt$x),mean(dt$y))))
lines(df_ell)
abline(a=0,b=1)

The line y=x should pass through the major axis of the ellipse due the covariance structure and the equal means.

In a square graphic window, everything seems fine: enter image description here

However, if the window is resized to make it no longer square, the ellipse seems to orient itself away from the line:

enter image description here

What is causing this to happen and is it expected behaviour ?

Robert Long
  • 5,722
  • 5
  • 29
  • 50
  • 2
    Draw the `y=x` line. What's the angle between the line and the `x` axis? Then resize the window, like you did in this question. What's the angle now? – nicola Mar 02 '15 at 20:25
  • 1
    related: http://stackoverflow.com/questions/4587794/drawing-non-intersecting-circles , http://stackoverflow.com/questions/6322603/trying-to-draw-circles-based-on-distance-between-points ; `MASS:eqscplot` may be useful. – Ben Bolker Mar 02 '15 at 21:19

1 Answers1

10

This is an optical illusion. Ellipses look a bit strange when the coordinates aren't square.


Note that your ellipse is based on the estimates from the sample, rather than the true underlying values, so it's not quite aligned properly to start with.

df_ell2 <- data.frame(ellipse(0.7, scale=c(30,30), centre=c(30,30)), npoints=101)

Now plot the ellipse with tangent lines as well as its major axis:

plot(dt$x,dt$y)
lines(df_ell2)
abline(0, 1)
abline(df_ell2[1,1]*2, -1)
abline(df_ell2[51,1]*2, -1)

ellipse with major axis and tangents

Hopefully the tangent lines let you see that the ellipse is properly aligned, but skewed by the aspect ratio.

pete
  • 2,327
  • 2
  • 15
  • 23
  • 3
    Another possibly-helpful thing to observe is that the set of points that lie exactly on the ellipse is the same on the square plot as on the oblong plot. – James Trimble Mar 02 '15 at 21:17