[R] Visualising SOM as hexagonal heatmaps
Adam Szałucha
adam.szalucha at gmail.com
Tue Aug 20 10:18:33 CEST 2013
I have a kohonen object generated with grid parameters grid =
somgrid(20, 20, "hexagonal"). Standard plot shows the codebook vectors
for all variables. I want to have a hexagonal heatmap for each
variable.
I found in Applied Spatial Data Analysis with R code to generate hexagonal grid.
library("sp")
data(meuse.grid)
gridded(meuse.grid) = ~x + y
HexPts <- spsample(meuse.grid, type = "hexagonal", cellsize = 200)
spplot(meuse.grid["dist"], sp.layout = list("sp.points", HexPts, col = 1))
HexPols <- HexPoints2SpatialPolygons(HexPts)
df <- as.data.frame(meuse.grid)[overlay(meuse.grid, HexPts),]
HexPolsDf <- SpatialPolygonsDataFrame(HexPols, df, match.ID = FALSE)
spplot(HexPolsDf["dist"])
And modified it to work with my kohonen object.
gridgminy=gminy.som$grid$pts
gridgminy=data.frame(gridgminy)
gridgminy=cbind(gridgminy,gminy.som$codes)
gridded(gridgminy) = ~x + y
gxx <- spsample(gridgminy, type = "hexagonal", cellsize = 0.99)
HexPolsGminy <- HexPoints2SpatialPolygons(gxx)
dfGminy <- as.data.frame(gridgminy)[overlay(gridgminy, gxx),]
HexPolsDfGminy <- SpatialPolygonsDataFrame(HexPolsGminy, dfGminy,
match.ID = FALSE)
spplot(HexPolsDfGminy["NGO"])
But there are some problems. Firstly the line
gxx <- spsample(gridgminy, type = "hexagonal", cellsize = 0.99)
works randomly. Sometimes it works good and I have full grid
https://dl.dropboxusercontent.com/u/4723921/Screenshots/zupb.png
sometimes it generates grid partly like that
http://dl.dropbox.com/u/4723921/Screenshots/mc3e.png
or like that
http://dl.dropbox.com/u/4723921/Screenshots/6lbh.png
Why does it happen?
Secondly what is the parameter cellsize mean? Is it hexagon area or is
it hexagon side?
Thirdly is there any tool to make selected sides bolder, to mark the clusters?
Thanks
Adam Szałucha
More information about the R-help
mailing list