ellipseFromScatter: Create segments of an ellipse around points on a 2D plane

Description Usage Arguments Value Examples

View source: R/ellipseFromScatter.R

Description

Create segments of an ellipse around points on a 2D plane

Usage

1
2
ellipseFromScatter(in.mat, in.group, in.col.sel = 1:2, in.scale = 1,
  in.prob = 0.68)

Arguments

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 obs.scale in ggbiplot manual https://www.rdocumentation.org/packages/ggbiplot/versions/0.55/topics/ggbiplot)

in.prob

size of the ellipse in Normal probability (see param ellipse.prob in ggbiplot manual)

Value

data frame with first two columns with corrdinates of points of an ellipse, and column 'group' with groupings as provided by 'in.group' vector.

Examples

 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)

dmattek/tca-package documentation built on Dec. 10, 2019, 4:10 p.m.