require(kohonen)
data(clusters)
c_grid <- kohonen::somgrid(xdim = 5, ydim = 5,
topo = 'rectangular')
c_som <- kohonen::som(as.matrix(clusters[,1:5]), grid = c_grid)
c_data_net <- som_model(c_som)
require(ggplot2)
ggplot() +
geom_segment(data=c_data_net$edges_s,
aes(x=x, xend=xend, y=y, yend=yend)) +
geom_point(data=c_data_net$data, aes(x=map1, y=map2),
colour="orange", size=2, alpha=0.5)
Run the code above in your browser using DataLab