I've been using self-organising map (SOM) visualisation in R as a preliminary clustering process.
However, I've noticed that SOM visualisation methods are built for 'SOM objects.' But, is it possible to replicate a SOM grid but without a SOM object in ggplot?
So, for example, is it possible to recreate a SOM-like 9-node hexagonal grid in ggplot with data from a single variable embedded inside, but without the SOM object provided below?
Therefore, I am really just looking to use a visual equivalent for summary stats, but without the need for the SOM object.
I've provided some mock data that I'd like to put in a SOM-like 9-node visual format, but I've also provided the data that generated my original SOM.
All help would be appreciated.
####################################
#SOME DATA FOR A POTENTIAL GRID
####################################
#A SINGLE RANKED VARIABLE
RankVar = rep(0:5, times = 108)
RankVar <- sample(RankVar)
# NODE ID TO BE ASSIGNED TO EACH OF THE 9 NODES
Node = rep(1:9, times = 72)
Node <- sample(Node)
DAT <- data.frame(RankVar, Node)
DAT <- data.frame(lapply(DAT, function(x) as.numeric(as.character(x))))
###################################
#MY SOM ROUTINE
###################################
install.packages("aweSOM")
install.packages("kohonen")
install.packages("RColorBrewer")
library(aweSOM)
library(kohonen)
library(RColorBrewer)
#DATA
X1 <- rep(1:3, times = 100)
X1 <- sample(X1)
X2 <- rep(1:3, times = 100)
X2 <- sample(X2)
X3 <- rep(1:3, times = 100)
X3 <- sample(X3)
X4 <- rep(1:3, times = 100)
X4 <- sample(X4)
X5 <- rep(1:3, times = 100)
X5 <- sample(X5)
Dat <- data.frame(X1, X2, X3, X4, X5)
Dat <- data.frame(lapply(Dat, function(x) as.numeric(as.character(x))))
Dat <- as.matrix(Dat)
#SET SEED
set.seed(145)
#SOM INITIALISATION
init <- somInit(Dat, 3, 3)
#SOM OBJECT
SOM <- kohonen::som(Dat, grid = kohonen::somgrid(3, 3, "hexagonal"),
rlen = 100, alpha = c(0.05, 0.01),
dist.fcts = "manhattan", init = init, keep.data = TRUE)
#CLUSTERING ON THE SOM
threeclusters3x3 <- cluster::pam(SOM$codes[[1]], 3)
clus3x3 <- threeclusters3x3$clustering
#PLOTTING THE SOM
plot < - aweSOMplot(som = SOM, type = "Barplot", data = Dat,
variables = c("X1", "X2", "X3", "X4", "X4"),
superclass = clus3x3,
showAxes = FALSE,
values = "median",
palsc = "Blues",
palvar = "Greys")
plot
####