Learn R Programming

emuR (version 2.4.0)

classplot: Produce a classification plot from discriminant or SVM modelling

Description

The function classifies all point specified within the ranges of xlim and ylim based on the training model specified in model. It then produces a two-dimensional plot colour-coded for classifications.

Usage

classplot(
  model,
  xlim,
  ylim,
  N = 100,
  pch = 15,
  col = NULL,
  legend = TRUE,
  position = "topright",
  bg = "gray90",
  ...
)

Arguments

model

A two-dimensional training model output from qda(), lda() of MASS package , or svm() of e1071 package

xlim

A vector of two numeric elements specifying the range on the x-axis (parameter 1) over which classifications should be made

ylim

A vector of two elements specifying the range on the y-axis (parameter 2) over which classifications should be made

N

A vector of one numeric element which specifies the density of classification (greater N gives higher density). The default is 100.

pch

A single element numeric vector specifying the plotting symbol to be used in the classification plot. Defaults to 15.

col

Either Null in which case the colours for the separate classes are col = c(1, 2, ...n) where n is the number of classes; or else a vector specifying the desired colours that is the same length as there are classes.

legend

A single element logical vector specifying whether a legend should be drawn. Defaults to TRUE

position

A single element vector specifying the position in the figure where the legend should be drawn. Defaults to "topright"

bg

A single element vector specifying the background colour on which the legend should be drawn.

...

Further arguments to plot.

Author

Jonathan Harrington

See Also

qda, lda, svm of e1071 package. There is a function plot.svm which produces a prettier plot for SVMs.

Examples

Run this code

library(MASS)
# Data from female speaker 68
temp = vowlax.spkr=="68"
# Quadratic discriminant analysis
fm.qda = qda(vowlax.fdat.5[temp,1:2], vowlax.l[temp])
# Linear discriminant analysis
fm.lda = lda(vowlax.fdat.5[temp,1:2], vowlax.l[temp])

xlim=c(0,1000)
ylim=c(0,3000)

oldpar = par(mfrow=c(1,2))
classplot(fm.qda, xlim=xlim, ylim=ylim, main="QDA")
classplot(fm.lda, xlim=xlim, ylim=ylim, main="LDA")

par(oldpar)


# install.packages("e1071")
# library(e1071)
# Support vector machine
if (FALSE) fm.svm = svm(vowlax.fdat.5[temp,1:2], factor(vowlax.l[temp]))
if (FALSE) xlim = range(vowlax.fdat.5[temp,1])
if (FALSE) ylim = range(vowlax.fdat.5[temp,2])
if (FALSE) classplot(fm.svm, xlim=xlim, ylim=ylim, xlab="F1", ylab="F2", main="SVM")          

Run the code above in your browser using DataLab