Description Usage Arguments Value See Also Examples
Fits an ellipse to data using conicfit
package
1 | Ellipsefit(data, x, y, coords = FALSE, bbox = FALSE)
|
data |
Name of data frame |
x |
name of x-vector in data |
y |
names of y-vector in data |
coords |
Logical. If TRUE, function returns a list of ellipse fit parameters and coordinates of the resulting ellipse. If FALSE, returns the ellipse fit parameters only. Default is FALSE. |
bbox |
Logical. If TRUE, function returns the extremes of the ellipse coordinates. These coordinares can be used to draw a bounding box around the ellipse. Only available when coords = TRUE. Default is FALSE. |
Either a data frame with the fit parameters for the ellipse (Default). If coords = TRUE
a list with two data frames, the fit parameters and the coordinates to draw the ellipse.
Fit parameters are:
The X coordinate of the center of the ellipse.
The Y coordinate of the center of the ellipse.
The distance from the center to the perimenter along the major axis.
The distance from the center to the perimenter along the minor axis.
The tilt angle of the ellipse.
The area of the ellipse.
The goodness-of-fit, R2, of the ellipse.
If bbox = TRUE
, in addition to the above, returns a data frame with the extreme values of the coordinates as the bounding box of the ellipse.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ## Not run:
Ellipsefit(eg.hour, temp.hour, Pp.hour, coords = TRUE)
Ellipsefit(eg.hour, temp.hour, Pp.hour)
## End(Not run)
mydata <- data.frame(x = c(5.92, 5.37, 3.16, 0.71, -0.29, -1.14, -0.8291667, 4.14, 10.74, 18.97, 21.66, 21.57, 21.56, 23.15, 24.17, 24.10, 23.26, 19.39, 12.31, 6.11, 7.49, 5.79, 2.66, 1.01),
y = c(0.14, 0.14, 0.10, 0.08, 0.08, 0.08, 0.12, 0.22, 0.36, 0.43, 0.42, 0.42, 0.43, 0.42, 0.37, 0.32, 0.26, 0.20, 0.12, 0.10, 0.14, 0.11, 0.07, 0.05))
ell <- Ellipsefit(mydata, x, y, coords = TRUE, bbox = TRUE)
coord <- ell$Coord
bbox <- ell$Bbox
plot(y ~ x, data = mydata, ylim = c(0, 0.5), xlim = c(-2, 25))
lines(y ~ x, data = coord, col = "blue")
abline(v = bbox$x, h = bbox$y, col = "red")
# comparison with ellipse-function from car::ellipse
par(new = TRUE)
# draw elliptical contours at the 0.5 probability or confidence level.
car::dataEllipse(mydata$x, mydata$y, levels = 0.5, ylim = c(0, 0.5), xlim = c(-2, 25))
# Calculate bounding box area to compare to ellipse area
bbox.area <- (bbox$x[2] - bbox$x[1]) * (bbox$y[2] - bbox$y[1])
area.ratio <- ell$Para$Area / bbox.area
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.