[R] Adding axis to an ellipse: "ellipse" package

Rolf Turner rolf.turner at xtra.co.nz
Wed Sep 28 09:29:10 CEST 2011


On 28/09/11 04:53, Antoine wrote:
> Dear list members,
>
> This might be a silly question but I just can't figure it out. I am using
> the "ellipse" package on covariance matrices. I would simply like to plot my
> ellipses WITH its two axis ploted as well. These axis represents the 2 eigen
> vectors of my matrix and it is important that I can graphically show them.
> Is there an easy way to do so?

Pretty easy.

* Calculate your eigenvalues and vectors using eigen().

* Rescale the vectors by multiplying them by the square
root of the corresponding eigenvalues, and by the constant
corresponding to the confidence level --- e.g. sqrt(qchisq(0.95,2))
for the usual 95% confidence level.

* Add these vectors to the ellipse plot, using segments().
E.g. if your rescaled eigenvectors are v1 and v2, just do:

     segments(-v1[1],-v1[2],v1[1],v1[2])

and

     segments(-v2[1],-v2[2],v2[1],v2[2])

     cheers,

         Rolf Turner



More information about the R-help mailing list