plot-methods: Plot method for S4 class 'SOMnn'

plot,SOMnn,ANY-methodR Documentation

Plot method for S4 class SOMnn

Description

Creates a plot of the hexagonal som in the model of type SOMnn.

Usage

## S4 method for signature 'SOMnn,ANY'
plot(
  x,
  title = TRUE,
  col = NA,
  onlyDefCols = FALSE,
  edit.cols = FALSE,
  show.legend = TRUE,
  legend.loc = "bottomright",
  legend.width = 4,
  window.width = NA,
  window.height = NA,
  show.box = TRUE,
  show.counter.border = 0.98,
  predict = NULL,
  add = FALSE,
  pch.col = "black",
  pch = 19,
  ...
)

Arguments

x

trained som of type SOMnn.

title

logical; if TRUE, slots name and date are used as main title.

col

defines colours for the classes of the dataset. Possible values include: NA: default value; colours are generated with rainbow, a vector of colour definitions or a data.frame with categories in the first and respective colours in the second column.

onlyDefCols

logical; if TRUE, only categories are plotted, for which colours are defined. Default: FALSE.

edit.cols

logical; if TRUE, colour definitions can be edited interactively before plotting. Default: FALSE.

show.legend

logical; if TRUE, a legend is displayed,. Default: TRUE.

legend.loc

Legend position as specified for legend. Default is "bottomright".

legend.width

size of the legend.

window.width

Manual setting of window width. Default is NA.

window.height

Manual setting of window height. Default is NA.

show.box

Show frame around the plot . Default is TRUE.

show.counter.border

Percentile as limit for the display of labels in the pie charts. Default is 0.98. Higher counts are displayed as numbers in the neuron.

predict

data.frame as returned by the som.nn::predict function or a data.frame or matrix that follows the specification: If columns x and y exist, these are used as coordinates for the traget neuron; otherwise the first two columns are used. Default: NULL.

add

logical; if TRUE, points are plotted on an existing plot. This can be used to stepwise plot points of different classes with different colours or symbols.

pch.col

Colour of the markers for predicted samples.

pch

Symbol of the markers for predicted samples.

...

More parameters as well as general plot parameters are allowed; see par.

Details

In addition to the required parameters, many options can be specified to plot predicted samples and to modify colours, legend and scaling.

Examples

## get example data and add class labels:
data(iris)
species <- iris$Species

## train with default radius = diagonal / 2:
rlen <- 500
som <- som.nn.train(iris, class.col = "Species", kernel = "internal",
                    xdim = 15, ydim = 9, alpha = 0.2, len = rlen, 
                    norm = TRUE, toroidal = FALSE)


## continue training with different alpha and radius;
som <- som.nn.continue(som, iris, alpha = 0.02, len=500, radius = 5)
som <- som.nn.continue(som, iris, alpha = 0.02, len=500, radius = 2)

## predict some samples:
unk <- iris[,!(names(iris) %in% "Species")]

setosa <- unk[species=="setosa",]
setosa <- setosa[sample(nrow(setosa), 20),]

versicolor <- unk[species=="versicolor",]
versicolor <- versicolor[sample(nrow(versicolor), 20),]

virginica <- unk[species=="virginica",]
virginica <- virginica[sample(nrow(virginica), 20),]

p <- predict(som, unk)
head(p)

## plot:
plot(som)
dev.off()
plot(som, predict = predict(som, setosa))
plot(som, predict = predict(som, versicolor), add = TRUE, pch.col = "magenta", pch = 17)
plot(som, predict = predict(som, virginica), add = TRUE, pch.col = "white", pch = 8)


som.nn documentation built on May 29, 2024, 6:50 a.m.