Description Usage Arguments Value Examples
View source: R/ellipseFromScatter.R
Create segments of an ellipse around points on a 2D plane
1 2 | ellipseFromScatter(in.mat, in.group, in.col.sel = 1:2, in.scale = 1,
in.prob = 0.68)
|
in.mat |
matrix with point coordinates. Rows correspond to points, columns to dimensions. |
in.group |
vector with grouping. Must be of the same length as the number of rows in the input matrix. |
in.col.sel |
vector to select columns from the input matrix. Must be of length 2. |
in.scale |
scale factor to apply to observations (see param |
in.prob |
size of the ellipse in Normal probability (see param |
data frame with first two columns with corrdinates of points of an ellipse, and column 'group' with groupings as provided by 'in.group' vector.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ## Draw red ellipse around scatter plot
n.pts = 50
n.cols = 2
m.gauss = matrix(rnorm(n.pts * n.cols), n.pts)
df.ell = ellipseFromScatter(m.gauss, rep(1, n.pts))
require(ggplot2)
ggplot(as.data.frame(m.gauss), aes(V1, V2)) +
geom_point() +
geom_path(data = df.ell, aes(X1, X2), color = 'red')
## Fill the ellipse with colour
require(dplyr)
df.hull <- df.ell %>%
do(.[chull(.[1:2]), ])
ggplot(as.data.frame(m.gauss), aes(V1, V2)) +
geom_point() +
geom_polygon(data = df.hull, aes(X1, X2), color = 'red', fill = 'red', alpha = 0.5)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.