Extracting the HTML colour code for each node of a Kohonen plot

118 views Asked by At

I am using the following script to plot a SOM and I would like to extract the HTML colour code corresponding to each node.

It doesn't seem to be in the som_model s3 object.

Any idea?

library(kohonen)

data<-matrix(c(-0.406,-0.406,-0.406,-0.406,2.463,-0.406,-0.406,2.463,-0.406,-0.406,-0.406,-0.406,
  -0.406,-0.406,-0.406,-0.406,-0.406,-0.406,-0.406,-0.406,0.4188448,1.6027146,0.7208751,
  0.7724322,0.5655424,-1.6969826,0.3429044,0.396769,0.3224141,-0.7324542,-0.5303228,0.9943725,
  -0.0324817,1.321637,-1.1985506,-0.3409802,-0.1393889,-0.3964047,0.9597519,-0.2443682), ncol=2)    

som_grid <- somgrid(xdim = 4, ydim=4, topo="hexagonal")

som_model <- som(data, 
                 grid=som_grid, 
                 rlen=100, 
                 alpha=c(0.05,0.01), 
                 keep.data = TRUE,
                 n.hood='circular')

plot(som_model,type="count")

The output I am looking for would be a list/vector with the colour code for each node: "#0000FF", "#FF0000"...

1

There are 1 answers

0
hrbrmstr On

The plot call is really a call to plot.kohonen and that, in turn, calls plot.kohprop to setup some plot aesthetics, including the color scheme . The default color scheme is heat.colors + gray. For your case, you can do heat.colors(3) and then look at som_model$grid to determine the color mapping.

You can see what plot.kohprop does by just entering the function name sans parens at an R console.