ell: Calculate coordinates of an ellipse

Description Usage Arguments Value Author(s) See Also Examples

View source: R/fun.R

Description

ell is a utility function used to calculate the (X, Y) coordinates of a 2D ellipse for the purpose of drawing statistical diagrams and plots.

ellplus can produce, in addition to the points of an ellipse, the conjugate axes corresponding to a chol or other decomposition and the surrounding parallelogram defined by these axes.

Usage

1
2
3
ell(center, shape, radius = 1, n = 100)

ellplus(center = rep(0, 2), shape = diag(2), radius = 1, n = 100, angles = (0:n) * 2 * pi/n, fac = chol, ellipse = all, diameters = all, box = all, all = FALSE)

Arguments

center

X,Y location of the center of the ellipse

shape

A 2x2 matrix, typically a covariance matrix of data (for a data ellipse), or a covariance matrix of estimated parameters in a model (for a confidence ellipse).

radius

Radius of the ellipse-generating unit circle. The default, radius=1 corresponds to a "standard" ellipse.

n

Number of points on the unit circle used to calculate the ellipse

angles

Angles around the unit circle used to calculate the ellipse

fac

A function defining the conjugate axes used to transform the unit circle into an ellipse. The default, chol, uses the right Cholesky factor of shape.

ellipse

Logical to indicate if the points on the ellipse should be returned

diameters

Logical to indicate if the points defining the ends of the conjugate axes of the ellipse should be returned

box

Logical to indicate if the points on the conjugate-axes bounding box should be returned

all

Logical to request all of ellipse, diameters and box. If FALSE, only the components specified separately by ellipse, diameters and box are returned.

Value

Returns a 2-column matrix of (X,Y) coordinates suitable for drawing with lines().

For ellplus, when more than one of the options ellipse, diameters, and box is TRUE, the different parts are separated by a row of NA.

Author(s)

Georges Monette

See Also

cell, dell, dellplus,

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
plot( x=0,y=0, xlim = c(-3,3), ylim = c(-3,3),
      xlab = '', ylab = '', type = 'n', asp=1)
abline( v=0, col="gray")
abline( h=0, col="gray")
A <- cbind( c(1,2), c(1.5,1))
W <- A %*% t(A)    
    
lines( ell(center=c(0,0), shape = W ), col = 'blue', lwd=3)
lines( ellplus(center=c(0,0), shape = W, box=TRUE, diameters=TRUE ), col = 'red')

# show conjugate axes for PCA factorization
pca.fac <- function(x) {
    xx <- svd(x)
    ret <- t(xx$v) * sqrt(pmax( xx$d,0))
    ret 
}

plot( x=0,y=0, xlim = c(-3,3), ylim = c(-3,3),
      xlab = '', ylab = '', type = 'n', asp=1)
abline( v=0, col="gray")
abline( h=0, col="gray")
lines( ell(center=c(0,0), shape = W ), col = 'blue', lwd=3)
lines( ellplus(center=c(0,0), shape = W, box=TRUE, diameters=TRUE, fac=pca.fac ), col = 'red')

gmonette/spida documentation built on May 17, 2019, 7:25 a.m.