sl.points2ellipse | R Documentation |
Draw an ellipse representing the cumulative distribution function of a bivariate normal distribution fitted to points on a sphere based on the covariance matrix.
sl.points2ellipse <- function (lon = NULL, lat = NULL, prob.within = 0.95, npoints = 360, return.ellispecs = F, Rsphere = 1)
lon |
a numeric vector specifying the longitudes of the points. |
lat |
a numeric vector specifying the latitudes of the points. |
prob.within |
a numeric scalar specifying the integrated probability to be enclosed by the ellipse. |
npoints |
an integer scalar specifying the number of points comprising the border of the ellipse. |
return.ellispecs |
a logical value specifying if area and semi-major and -minor axis of the resulting ellipse should be returned. |
Rsphere |
a numeric scalar defining the radius of the sphere, needed for calculating the area of the ellipse, default is |
The points are rotated so that their barycenter is the new pole. Then, the function ellipse
from the package mixtools
is used to derive the ellipse on the xy-plane. Finally, the points are projected back onto the sphere with x,y fixed.
The latter implies that a very large ellipse obtained due to a large prob.within
or due to excessive spread of the point cloud (e.g., spanning more than one hemisphere) will cause an error. However, in that case the assumptions underlying in the projection from the sphere to the xy-plane and back are violated too heavily anyway.
Note that the area of the ellipse is calculated in the projection on the xy-plane, i.e. the curvature is ignored.
A list with the following elements:
lon |
a numeric vector giving the longitudes of the points describing the ellipse |
lat |
a numeric vector giving the longitudes of the points describing the ellipse |
area |
a numeric scalar giving the area of the ellipse - only if |
a , b |
numeric scalars for semi-major and semi-minor axis length - only if |
Helge Goessling, modified by Simon Reifenberg
mixtools::ellipse
lon0 = rnorm(100,sd=15)
lat0 = rnorm(100,sd=5)
angle = pi/6
lon = lon0 * cos(angle) - lat0 * sin(angle)
lat = lon0 * sin(angle) + lat0 * cos(angle)
res = sl.points2ellipse(lon=lon,lat=lat,prob.within=0.9)
plot(lon,lat)
lines(res$lon,res$lat,col="red")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.