State-by-month heatmap with normalization and ordering options
Source:R/plot.R
plot_state_month_heatmap.RdCreates a heatmap of an indicator across states and months. This supports internal normalization (Min-Max or Z-score) and flexible row ordering (Clustering, Peak Month, or Alphabetical).
Usage
plot_state_month_heatmap(
data,
fill_col = "value",
state_col = "state",
month_col = "month",
title = NULL,
fill_label = "Value",
palette = "Spectral",
direction = -1,
order_by = c("cluster", "peak_month", "alphabetical", "none"),
normalize = c("none", "min-max", "z-score"),
text_size = NULL,
facet_col = NULL
)Arguments
- data
A data frame containing state, month, and value columns.
- fill_col
Name of the column to use for heatmap fill. Default
"value".- state_col
Name of the column for states (Y-axis). Default
"state".- month_col
Name of the column for months (X-axis). Default
"month".- title
Plot title. Default
NULL.- fill_label
Legend title. Default
"Value".- palette
A ColorBrewer palette name (e.g., "Spectral", "YlOrRd").
- direction
Palette direction (1 or -1). Default
-1.- order_by
Character. Method to order states:
"cluster": Ward's D2 hierarchical clustering (standard default)."peak_month": Orders states by the month in which they reach their maximum value. January peaks will appear at the top."alphabetical": Simple A-Z order."none": Keeps the current factor levels in the data.
- normalize
Character. Normalization to apply within each state:
"none": Absolute values (default)."min-max": Scaled 0 to 1 (reveals timing of peaks)."z-score": Standardized (mean=0, sd=1).
- text_size
Numeric. Size of text labels inside tiles. Default
NULL.- facet_col
Optional column to facet by. Default
NULL.