panel.elli | R Documentation |
lattice panel functions for plotting grouped ellipse and outlier
panel.elli(x, y, groups = NULL,conf.level = 0.975, ...)
panel.elli.1(x, y, subscripts, groups=NULL, conf.level = 0.975,
ep=0, com.grp=NULL, no.grp=NULL, ell.grp=NULL, ...)
panel.outl(x, y, subscripts, groups=NULL, conf.level = 0.975, labs, ...)
x , y |
Variables to be plotted. |
conf.level |
Confident level for ellipse |
groups , subscripts |
Internal parameters for Lattice. |
labs |
Labels for potential outliers. |
ep |
An integer for plotting ellipse. |
com.grp |
A list of characters to select which combination of groups to be plotted. |
no.grp |
A list of characters to select which individual group
not to be plotted. Note it will be overridden by |
ell.grp |
Another categorical vector used for plotting ellipse.
If provided, |
... |
Further arguments. See corresponding entry in
|
panel.elli
is modified from function
panel.ellipse
in package latticeExtra.
panel.elli.1
gives more control on how to plot ellipse for the
current group. It also provides an option to plot ellipse based on
another user-defined groups.
panel.outl
plots the labels of data points outside the ellipse.
These data points can be treated as potential outliers.
Retuns objects of class "trellis"
.
panel.elli.1
can be called by functions grpplot
,
pcaplot
, mdsplot
, pca_plot_wrap
,
mds_plot_wrap
, pls_plot_wrap
and lda_plot_wrap
by
passing argument of ep
. See examples of these function for
details.
Wanchang Lin
grpplot
, pcaplot
, mdsplot
.
library(lattice)
data(iris)
## =====================================================================
## Examples of calling 'panel.elli' and 'panel.outl'
xyplot(Sepal.Length ~ Petal.Length, data = iris, groups=Species,
par.settings = list(superpose.symbol = list(pch=c(15:17)),
superpose.line = list(lwd=2, lty=1:3)),
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.elli(x, y, ..., type="l",lwd=2)
panel.outl(x,y, ...)
},
auto.key = list(x = .1, y = .8, corner = c(0, 0)),
labs=rownames(iris), conf.level=0.9,adj = -0.5)
## Without groups
xyplot(Sepal.Length ~ Petal.Length, data = iris,
par.settings = list(plot.symbol = list(cex = 1.1, pch=16)),
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.elli(x, y, ..., type="l", lwd = 2)
panel.outl(x,y, ...)
},
auto.key = list(x = .1, y = .8, corner = c(0, 0)),
labs=rownames(iris), conf.level=0.9,adj = -0.5)
## With conditioning
xyplot(Sepal.Length ~ Petal.Length|Species, data = iris,
par.settings = list(plot.symbol = list(cex = 1.1, pch=16)),
layout=c(2,2),
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.elli(x, y, ..., type="l", lwd = 2)
panel.outl(x,y, ...)
},
auto.key = list(x = .6, y = .8, corner = c(0, 0)),
adj = 0,labs=rownames(iris), conf.level=0.95)
## =====================================================================
## Examples of 'panel.elli.1'
xyplot(Sepal.Length ~ Petal.Length, data = iris, groups=Species,
## ---------------------------------------------------
## Select what to be plotted.
ep=2,
## com.grp = list(a="setosa",b=c("versicolor", "virginica")),
## no.grp = "setosa", ## Not draw ellipse for "setosa"
## ---------------------------------------------------
par.settings = list(superpose.symbol = list(pch=c(15:17)),
superpose.line = list(lwd=2, lty=1:3)),
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.elli.1(x, y, ...)
panel.outl(x,y, ...)
},
auto.key = list(points = TRUE, rectangles = FALSE, space = "right"),
adj = 0,labs=rownames(iris), conf.level=0.95)
xyplot(Sepal.Length ~ Petal.Length, data = iris, groups=Species,
## ---------------------------------------------------
## Select what to be plotted.
ep=2,
## com.grp = list(a="setosa",b=c("versicolor", "virginica")),
no.grp = c("setosa","versicolor"),## Only draw "virginica"
## ---------------------------------------------------
par.settings = list(superpose.symbol = list(pch=c(15:17)),
superpose.line = list(lwd=2, lty=1:3)),
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.elli.1(x, y, ...)
},
auto.key = list(x = .1, y = .8, corner = c(0, 0)))
xyplot(Sepal.Length ~ Petal.Length, data = iris, groups=Species,
## ---------------------------------------------------
## Select what to be plotted.
ep=2,
com.grp = list(a="setosa",b=c("versicolor", "virginica")),
## no.grp = "setosa", ## Not draw ellipse for "setosa"
## ---------------------------------------------------
par.settings = list(superpose.symbol = list(pch=c(15:17)),
superpose.line = list(lwd=2, lty=1:3)),
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.elli.1(x, y, ...)
},
auto.key = list(x = .1, y = .8, corner = c(0, 0)))
xyplot(Sepal.Length ~ Petal.Length, data = iris, groups=Species, ep=1,
par.settings = list(superpose.symbol = list(pch=c(15:17)),
superpose.line = list(lwd=2, lty=1:3)),
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.elli.1(x, y, ...)
},
auto.key = list(points = TRUE, rectangles = FALSE, space = "right"))
## =====================================================================
## Another data set from package MASS
require(MASS)
data(Cars93)
## Plot ellipse based on original groups: DriveTrain
xyplot(Price~EngineSize, data=Cars93, groups=DriveTrain, ep=2,
par.settings = list(superpose.symbol = list(pch=c(15:17)),
superpose.line = list(lwd=2, lty=1:3)),
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.elli.1(x, y, ...)
},
auto.key = list(points = TRUE, rectangles = FALSE, space = "right"))
## But we want to plot ellipse using AirBags
xyplot(Price~EngineSize, data=Cars93, groups=DriveTrain,
ell.grp=Cars93$AirBags,
par.settings = list(superpose.symbol = list(pch=c(15:17)),
superpose.line = list(lwd=2, lty=1:3)),
panel = function(x, y, ...) {
panel.xyplot(x, y, ...)
panel.elli.1(x, y, ...)
},
auto.key = list(points = TRUE, rectangles = FALSE, space = "right"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.