View source: R/som.add.clusters.legend.R
som.add.clusters.legend | R Documentation |
Function to apply a legend of clusters to a SOM map image
som.add.clusters.legend(Nclus, color.scale)
Nclus |
the number of clusters to which put the legent |
color.scale |
the color scale used for the image |
Called for its effect.
Stefano Motta stefano.motta@unimib.it
#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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.