MyNixOS website logo
Description

Hinton Diagrams for 'ggplot2'.

Provides a 'ggplot2' extension for drawing Hinton diagrams, a visualisation technique for numerical matrices in which the area of each square is proportional to the magnitude of the corresponding entry. For signed data, white squares indicate positive values and black squares indicate negative values on a grey background. Hinton diagrams are especially useful for visualising PCA weight matrices, correlation matrices, and transition matrices.

gghinton

Hinton diagrams for ggplot2.

A Hinton diagram visualises a numerical matrix. Each element is displayed as a square and where the square's area is proportional to the absolute value of the element. Positive values are white, negative values are black, on a grey background. This simple clear perceptual mapping makes interpretation of the structure of the matrix easy.

pak::pkg_install("robin-foster-rf/gghinton")
# install.packages("gghinton")  # once on CRAN

library(gghinton)

m <- matrix(runif(10*10, -1, 1), nrow = 10)

matrix_to_hinton(m) |>
  ggplot(aes(x = col, y = row, weight = weight)) +
  geom_hinton() +
  scale_fill_hinton() +
  coord_fixed() +
  theme_hinton()

Why not a heatmap?

HeatmapHinton diagram
Encodes magnitudevia colour intensityvia square area
Encodes signrequires diverging palettewhite vs black
Works for colourblind readersdepends on paletteyes
Near-zero valuesinvisible colourinvisible square
Works at a glancepartiallyyes

Colour saturation is a notoriously unreliable channel for magnitude judgements. Square area is not: humans compare areas accurately, pre-attentively. When you care about how big and which sign, a Hinton diagram beats a heatmap.

Heatmaps are better when: you have large matrices (> ~50x50, where at typical plotting sizes you would only have a handful of pixels per element), continuous gradients matter more than individual entries, or values are all positive and the magnitude range is narrow.

Installation

#development version:
pak::pkg_install("robin-foster-rf/gghinton")

# install.packages("gghinton")  # from CRAN (once available)

Core functions

FunctionPurpose
geom_hinton()Draw a Hinton diagram as a ggplot2 layer
stat_hinton()The underlying stat_* (for advanced use)
scale_fill_hinton()White/black colour scale for signed data
theme_hinton()Clean theme: removes grid lines
matrix_to_hinton()Convert a matrix to a tidy data frame
as_hinton_df()Generic converter (matrix, data.frame, table)

Key aesthetics

aes(x = col,    # column position
    y = row,    # row position (row 1 of the matrix is at the top)
    weight = w) # the value: determines size and colour

The scale_by parameter

# Default: each facet panel normalised independently
geom_hinton(scale_by = "panel")

# Global: all panels share the same scale, allows cross-panel comparison
geom_hinton(scale_by = "global")

Use cases

  • Correlation matrices: immediately spot large positive and negative correlations
  • Factor loadings: which variables load strongly on which factors
  • Transition matrices: Markov chain structure at a glance
  • PCA weight matrices: understand what a principal component captures

Design

gghinton follows standard ggplot2 extension conventions:

  • GeomHinton extends GeomRect
  • StatHinton computes rectangle bounds in compute_panel so normalization is consistent within each panel
  • Sign detection is automatic (no need to tell the package whether your data is signed)
Metadata

Version

0.1.0

License

Unknown

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows