Definition and purpose of a myGrid class object

Objects of class myGrid are made to display the SOM grid.

Basic functions on a myGrid class object

In this section, we will consider only the four basic functions that can be applied on a myGrid class object:

The initGrid function

The initGrid function initializes a new myGrid object. It has 3 arguments:

The following R code initializes a new myGrid object of square topology, x dimension 5 and y dimension 6, and distance type maximum.

first_grid <- initGrid(dimension = c(5,6), topo = "square", dist.type = "maximum")

The print.myGrid function

The myGrid object print function prints the main features of the chosen object in the console. The only argument is the object to be printed.

Considering the previously initialized grid, the print command is:

print(first_grid)
## 
##       Self-Organizing Map structure
## 
##         Features   :
##            topology     :  square 
##            x dimension  :  5 
##            y dimension  :  6 
##            distance type:  maximum

The summary.myGrid function

The myGrid object summary function is quite simple. It only prints the class of the object and then calls the print function previously described. The only argument is the object to be summarized.

summary(first_grid)
## 
## Summary
## 
##       Class            :  myGrid 
## 
##       Self-Organizing Map structure
## 
##         Features   :
##            topology     :  square 
##            x dimension  :  5 
##            y dimension  :  6 
##            distance type:  maximum

The plot.myGrid function

The myGrid object plot function draws the squared area corresponding to the object, in a new graphical window. It has 3 parameters:

plot(first_grid)

plot of chunk plotRainbowGrid

plot(first_grid) + ggplot2::scale_fill_manual(values = rep("white", 30))

plot of chunk plotRainbowGrid

my_palette <- colorRampPalette(c("white", "pink", "purple"))(30)
plot(first_grid, show.names = FALSE) + 
  ggplot2::scale_fill_manual(values = my_palette)

plot of chunk plotRainbowGrid

Hexagonal grids can be displayed similarly:

second_grid <- initGrid(dimension = c(4, 5), topo = "hexagonal")
plot(second_grid, names = paste0("N", 1:20)) + 
  ggplot2::ggtitle("Hexagonal SOM grid")

plot of chunk plotHexa

Session information

This vignette has been computed with the following environment:

sessionInfo()
## R version 3.6.3 (2020-02-29)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 18.04.4 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=fr_FR.UTF-8        LC_COLLATE=C              
##  [5] LC_MONETARY=fr_FR.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=fr_FR.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] SOMbrero_1.3   igraph_1.2.4.1
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.4.6         highr_0.8            pillar_1.4.3        
##  [4] compiler_3.6.3       tools_3.6.3          digest_0.6.20       
##  [7] lattice_0.20-41      lubridate_1.7.4      evaluate_0.14       
## [10] lifecycle_0.2.0      tibble_2.1.3         gtable_0.3.0        
## [13] checkmate_1.9.4      pkgconfig_2.0.2      png_0.1-7           
## [16] rlang_0.4.5          hexbin_1.27.3        xfun_0.13           
## [19] interp_1.0-33        metR_0.7.0           dplyr_0.8.3         
## [22] stringr_1.4.0        knitr_1.23           grid_3.6.3          
## [25] tidyselect_1.0.0     scatterplot3d_0.3-41 glue_1.4.0          
## [28] data.table_1.12.2    R6_2.4.1             farver_2.0.3        
## [31] ggplot2_3.3.0        purrr_0.3.3          deldir_0.1-25       
## [34] magrittr_1.5         scales_1.1.0         backports_1.1.4     
## [37] ggwordcloud_0.5.0    assertthat_0.2.1     mime_0.7            
## [40] colorspace_1.4-1     labeling_0.3         stringi_1.4.3       
## [43] munsell_0.5.0        markdown_1.0         crayon_1.3.4