Learn R Programming

GowerSom (version 0.1.0)

plot_Umatrix: Plot the U-Matrix of a Gower-SOM

Description

Visualizes the U-Matrix of a trained Gower-SOM using ggplot2. The U-Matrix reveals cluster boundaries and topological structures in the map.

Usage

plot_Umatrix(u_matrix, fill_palette = "C")

Value

A ggplot object displaying the U-Matrix as a heatmap.

Arguments

u_matrix

Numeric matrix as returned by gsom_Umatrix (n_rows x n_cols).

fill_palette

Character string, viridis option for the fill scale (default "C").

Details

The function reshapes the U-Matrix into long format and draws a raster heatmap with geom_raster. By default, it uses perceptually uniform viridis palettes for improved interpretability, but the palette can be changed through fill_palette.

See Also

gsom_Umatrix

Examples

Run this code
set.seed(1)
df <- data.frame(
  x1 = rnorm(20),
  x2 = rnorm(20),
  g  = factor(sample(letters[1:3], 20, TRUE))
)
fit <- gsom_Training(df, grid_rows = 3, grid_cols = 3,
                num_iterations = 5, batch_size = 4)
U <- gsom_Umatrix(fit$weights, n_rows = 3, n_cols = 3)
plot_Umatrix(U)

Run the code above in your browser using DataLab