Description Usage Arguments Value Examples
Plot interactive visualizations of self-organizing maps (SOM), as an html page. The plot can represent general map informations, or selected categorical or numeric variables (not necessarily the ones used during training). Hover over the map to focus on the selected cell or variable, and display further information.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | aweSOMplot(
som,
type = c("Hitmap", "UMatrix", "Circular", "Barplot", "Boxplot", "Radar", "Line",
"Color", "Pie", "CatBarplot"),
data = NULL,
variables = NULL,
superclass = NULL,
obsNames = NULL,
scales = c("contrast", "range", "same"),
values = c("mean", "median", "prototypes"),
size = 400,
palsc = c("Set3", "viridis", "grey", "rainbow", "heat", "terrain", "topo", "cm",
rownames(RColorBrewer::brewer.pal.info)),
palvar = c("viridis", "grey", "rainbow", "heat", "terrain", "topo", "cm",
rownames(RColorBrewer::brewer.pal.info)),
palrev = FALSE,
showAxes = TRUE,
transparency = TRUE,
boxOutliers = TRUE,
showSC = TRUE,
pieEqualSize = FALSE,
elementId = NULL
)
|
som |
'kohonen' object, a SOM created by the 'som' function. |
type |
character, the plot type. The default "Hitmap" is a population map. "UMatrix" plots the average distance of each cell to its neighbors, on a color scale. "Circular" (barplot), "Barplot", "Boxplot", "Radar" and "Line" are for numeric variables. "Color" (heat map) is for a single numeric variable. "Pie" (pie chart) and "CatBarplot" are for a single categorical (factor) variable. |
data |
data.frame containing the variables to plot. This is typically not the training data, but rather the unscaled original data, as it is easier to read the results in the original units, and this allows to plot extra variables not used in training. If not provided, the training data is used. |
variables |
character vector containing the names of the variable(s) to plot. The selected variables must be numeric for types "Circular", "Barplot", "Boxplot", "Radar", "Color" and "Line", or factor for types "Pie" and "CatBarplot". If not provided, all columns of data will be selected. If a numeric variable is provided to a "Pie" or "CatBarplot", it will be split into a maximum of 30 classes. |
superclass |
integer vector, the superclass of each cell of the SOM. |
obsNames |
character vector, names of the observations to be displayed when hovering over the cells of the SOM. Must have a length equal to the number of data rows. If not provided, the row names of data will be used. |
scales |
character, controls the scaling of the variables on the plot. The default "constrast" maximizes the displayed contrast by scaling the displayed heights of each variable from minimum to maximum of the displayed value. Alternatively, "range" uses the minimum and maximum of the observations for each variable, and "same" displays all variables on the same scale, using the global minimum and maximum of the data. |
values |
character, the type of value to be displayed. The default "mean" uses the observation means (from data) for each cell. Alternatively, "median" uses the observation medians for each cell, and "prototypes" uses the SOM's prototypes values. |
size |
numeric, plot size, in pixels. Default 400. |
palsc |
character, the color palette used to represent the superclasses as background of the cells. Default is "Set3". Can be "viridis", "grey", "rainbow", "heat", "terrain", "topo", "cm", or any palette name of the RColorBrewer package. |
palvar |
character, the color palette used to represent the variables. Default is "viridis", available choices are the same as for palsc. |
palrev |
logical, whether color palette for variables is reversed. Default is FALSE. |
showAxes |
logical, whether to display the axes (for "Circular", "Barplot", "Boxplot", "Star", "Line", "CatBarplot"), default TRUE. |
transparency |
logical, whether to use transparency when focusing on a variable, default TRUE. |
boxOutliers |
logical, whether outliers in "Boxplot" are displayed, default TRUE. |
showSC |
logical, whether to display superclasses as labels in the "Color" and "UMatrix" plots, default TRUE. |
pieEqualSize |
logical, whether "Pie" should display pies of equal size. The default FALSE displays pies with areas proportional to the number of observations in the cells. |
elementId |
character, user-defined elementId of the widget. Can be useful for user extensions when embedding the result in an html page. |
Returns an object of class htmlwidget.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | ## Build training data
dat <- iris[, c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")]
### Scale training data
dat <- scale(dat)
## Train SOM
### Initialization (PCA grid)
init <- somInit(dat, 4, 4)
ok.som <- kohonen::som(dat, grid = kohonen::somgrid(4, 4, 'hexagonal'),
rlen = 100, alpha = c(0.05, 0.01),
radius = c(6.08,-6.08), init = init,
dist.fcts = 'sumofsquares')
## Group cells into superclasses (PAM clustering)
superclust <- cluster::pam(ok.som$codes[[1]], 2)
superclasses <- superclust$clustering
## Population map ('Hitmap')
aweSOMplot(som = ok.som, type = 'Hitmap', superclass = superclasses)
## Plots for numerical variables
variables <- c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")
## Circular barplot
aweSOMplot(som = ok.som, type = 'Circular', data = iris,
variables= variables, superclass = superclasses)
## Barplot (numeric variables)
aweSOMplot(som = ok.som, type = 'Barplot', data = iris,
variables= variables, superclass = superclasses)
## Plots for categorial variables (iris species, not used for training)
## Pie
aweSOMplot(som = ok.som, type = 'Pie', data = iris,
variables= "Species", superclass = superclasses)
## Barplot (categorical variables)
aweSOMplot(som = ok.som, type = 'CatBarplot', data = iris,
variables= "Species", superclass = superclasses)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.