Original link:tecdat.cn/?p=18879
This is a hexagon heat map visualization program, the main use of knowledge RColorBrewer, Fields, that is, R in the visual drawing library.
This paper hopes that SOM results can be visualized as hexagon heat map. Let me show you how to create a hexagon heat map in R!
You must create your own variables based on the results of a self-organizing neural network (SOM). Input variable Heatmap_Matrix The Heatmap_Matrix variable is a matrix that can be used as a numerical representation of a heat map.
Thus, the matrix has the same number of rows as the SOM map and the same number of columns as the SOM map, and each value in the heat map represents a hexagon value. Here [1,1] will be the lower-left node (first row, first column), [1,2] will be the right-side node, will be the first left-side node in the second row [2,1], and so on. Thus, visually, the order runs from bottom left to top right, while in a matrix, it runs from top left to bottom right.
code
Library (RColorBrewer) # Use Brewer.pal Library (Fields) # Use designer.colors # Function to create polygons for each hexagon # Start with a matrix that will serve as a numerical representation of your heat map, Called Heatmap_Matrix x < -as.vector (map_Matrix) # this matrix has the same number of rows as the SOM map and the same number of columns as the SOM map, and each value in the heat map represents a hexagon value # where [1,1] will become the lower left node (first row, first column), [1,2] will be the right node [2,1] will be the first node to the left of the second row # so visually, Rows < -dim (map_Matrix)[1] Columns < -dim (map_Matrix)[2] # Rows < -dim (map_Matrix)[2] # 7)) # start drawing window, But does display all axes or points on the plot(0, 0, type =" n", axes = FALSE, xlim=c(0, Columns), ylim=c(0, Rows), xlab="", ylab= "", ColRamp < -rev (designer.colors(n=50, col=brewer.pal(9, col= 10)) "Spectral")) # Make a vector whose length (ColRamp) has a bin number between the minimum and maximum value of x. ColorCode < -rep ("#FFFFFF", length(x)) # default for (I in 1:length(x)) if (! Is.na (x[I])) ColorCode[I] < -colramp [which. Min (abs(Bins-x[I]))] # 1: Rows) { for (column in 0:( Columns - 1)) agon(column + offset, row - 1, ColorCode[row + Rows * column]) offset < -ifelse (offset, 0, 0.5)} zlim=c(min(x, na.rm=T), max(x, na.rm=T)))Copy the code
Able to read the meaning of color legend
At the end, create a legend and you’ll get a heat map similar to the one above.
Hopefully, my explanations and code will help you create your own beautiful heat maps in R.
Most welcome insight
1. Dynamic map visualization in R language: how to create beautifully animated graphs
2. Visual analysis of R language survival analysis
3.Python Data Visualization – Seaborn Iris Iris data
4. R language for buffon needle throwing (Buffon needle throwing) experiment simulation and dynamic
5. Visualization case of R language survival analysis data analysis
6. R language data visualization analysis case: Explore BRFSS data data analysis
7. Dynamic visualization in R language: make animated GIF video images of cumulative dynamic line charts of historical global average temperature
8. Case report of principal component Pca and T-SNE algorithm dimension reduction and visual analysis for R language high-dimensional data
9. Python topics LDA modeling and T-SNE visualization