geom_hinton() draws a Hinton diagram: a grid of squares whose area is
proportional to the magnitude of each value. For signed data, positive
values are shown as white squares and negative values as black squares on
a grey background. For unsigned (non-negative) data the background is
omitted and squares are drawn in black.
geom_hinton(
mapping = NULL,
data = NULL,
stat = "hinton",
position = "identity",
...,
scale_by = c("panel", "global"),
background = TRUE,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)stat_hinton(
mapping = NULL,
data = NULL,
geom = "hinton",
position = "identity",
...,
scale_by = c("panel", "global"),
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
A ggplot2 layer that can be added to a ggplot2::ggplot() object.
Set of aesthetic mappings created by ggplot2::aes().
The data to be displayed in this layer.
The statistical transformation to use. For geom_hinton() the
default is "hinton".
Position adjustment.
Other arguments passed on to ggplot2::layer().
"panel" (default) normalises each panel independently so
the largest value in a panel fills its cell. "global" uses the
largest value across all panels, enabling cross-panel magnitude comparison.
Logical. Draw a grey background rectangle for signed
data? Default TRUE. Set to FALSE to suppress the background.
If TRUE, rows where weight is NA are silently dropped
before computing square sizes. If FALSE (default), they are dropped
without a warning (ggplot2 will not render rectangles whose required
aesthetics are NA).
Logical. Should this layer be included in the legend?
If FALSE, overrides the default aesthetics rather than
combining with them.
The geometric object to use when drawing. For stat_hinton()
the default is "hinton".
geom_hinton() understands the following aesthetics (required aesthetics
are in bold):
x: column position (numeric or factor)
y: row position (numeric or factor)
weight: the value to display; determines square size and colour
alpha
colour (border colour; NA by default, no border)
fill (overrides the automatic sign-based colour)
linewidth
linetype
stat_hinton() adds the following columns to the data:
xmin, xmax, ymin, ymaxRectangle bounds for each square.
fill"positive", "negative", or "unsigned".
hinton_signedLogical; TRUE when the panel contains any negative
values. Read by GeomHinton to decide whether to draw the grey
background (after scale_fill_hinton() has already replaced the fill
labels, making fill == "negative" checks unreliable).
cell_w, cell_hInferred cell spacing used to size the background.
For squares to appear as squares on screen, add coord_fixed() to your
plot. Without it, the cells may appear rectangular if the plot's x and y
axes have different scales.
library(ggplot2)
m <- matrix(c(0.8, -0.3, 0.5, -0.9, 0.1, 0.6, 0.4, -0.7, 0.2), 3, 3)
df <- matrix_to_hinton(m)
ggplot(df, aes(x = col, y = row, weight = weight)) +
geom_hinton() +
scale_fill_hinton() +
coord_fixed() +
theme_hinton()
Run the code above in your browser using DataLab