Sie sind auf Seite 1von 2

Ellipse

This is code for plot ellipse.

### draw 2-D ellipse by package "car"


library(car)
library(MASS)
# here is one for 2-D
x <- mvrnorm(n = 100, mu = c(0,0), Sigma = diag(2))
plot(x)
ellipse(center = colMeans(x), shape = cov(x), radius = 2, add = TRUE, center.pch = FALSE)

x <- mvrnorm(n = 100, mu = c(0,0), Sigma = diag(2))


# lty 线条类型
dataEllipse(x = x[,1], y = x[,2], levels = 0.95,
center.pch = FALSE, lty=2, lwd = 1,
fill = TRUE, fill.alpha = 0.2,
grid = FALSE)

text(x = .5, y = .5, labels = "write text here")


text(-.5,-.5, expression(x[1]+ x[2]+ y^3+ alpha) )
# for more information about Mathematical Annotation in R
# refer to function "plotmath" in package "grDevices"
# http://sites.stat.psu.edu/~dhunter/R/html/grDevices/html/plotmath.html

### draw 3-D ellipsoid by package "rgl"


library(rgl)

## Warning: package 'rgl' was built under R version 3.1.3

Sigma <- matrix(data = c(10,3,0,3,2,0,0,0,1),


nrow = 3, ncol = 3)
Mean <- 1:3
x <- mvrnorm(n = 1000, mu = Mean, Sigma = Sigma)

open3d()

## wgl
## 1

plot3d(x, box = TRUE)


plot3d( ellipse3d(Sigma, centre = Mean), col = "green", alpha = 0.75, add = TRUE)

Das könnte Ihnen auch gefallen