data(iris)
cov <- cov(iris[,1:2])
mu <- colMeans(iris[,1:2])
radius <- sqrt(qchisq(0.68, 2))
plot(iris[,1:2], asp=1)
car::ellipse(mu, cov, radius = radius)
res <- ellipse.axes(cov, center=mu, level = 0.68,
labels = TRUE)
res
# try some options
plot(iris[,1:2], asp=1)
car::ellipse(mu, cov, radius = radius)
abline(h=mu[2], v=mu[1], col = "grey")
ellipse.axes(cov, centre=mu, level = 0.68,
labels = "Dim", label.ends = 1:4,
lwd = 2, lty = 2, col = "red",
cex = 1.5)
# draw arrows rather than lines
plot(iris[,1:2], asp=1)
car::ellipse(mu, cov, radius = radius)
ellipse.axes(cov, center=mu, level = 0.68,
type = "arrows", extend = 0.2)
Run the code above in your browser using DataLab