Learn R Programming

SOMMD (version 0.1.2)

som.add.clusters.legend: Add legend clusters

Description

Function to apply a legend of clusters to a SOM map image

Usage

som.add.clusters.legend(Nclus, color.scale)

Value

Called for its effect.

Arguments

Nclus

the number of clusters to which put the legent

color.scale

the color scale used for the image

Author

Stefano Motta stefano.motta@unimib.it

Examples

Run this code
#Read example SOM data
som_model <- readRDS(system.file("extdata", "SOM_HIFa.rds", package = "SOMMD"))
#Divide the SOM in the selected number of clusters
som_cl <- cutree(hclust(dist(som_model$codes[[1]], method="euclidean"), method="complete"), 4)
#Define a set of colors
colors <- c("#1f78b4", "#33a02c", "#e31a1c", "#ffff88", "#6a3d9a") 
#Plot the som with neurons colored according to clusters
plot(som_model, type = "mapping", bgcol=colors[som_cl], col=rgb(0,0,0,0), shape='straight', main="")
kohonen::add.cluster.boundaries(som_model, som_cl, lwd=5)
#Add legend to the plot
som.add.clusters.legend(Nclus=4, color.scale=colors)

Run the code above in your browser using DataLab