Map continuous values to diverging colors (dark red -> white -> dark green)

values_to_colors_continuous(
  x,
  labels = NULL,
  min = -3,
  max = 3,
  neutral_min = -0.5,
  neutral_max = 0.5,
  low = "#7f0000",
  mid = "#ffffff",
  high = "#006400",
  n = 201
)

Arguments

x

Numeric vector. Can be named or unnamed, but must align with labels by name (preferred) or by position (same length).

labels

Character vector of node labels (names to use in the result).

min

Minimum value that maps to the darkest red (values below are clipped).

max

Maximum value that maps to the darkest green (values above are clipped).

low

Color for low end (default dark red).

mid

Color for midpoint (default white).

high

Color for high end (default dark green).

n

Number of discrete colors used internally for the gradient.

Value

Named character vector of hex colors with names equal to labels.

Examples

z_values <- c(-2.5, -1, 0, 1, 2.5)
names(z_values) <- paste0("Node", 1:5)
colors <- values_to_colors_continuous(z_values)
print(colors)
#>     Node1     Node2     Node3     Node4     Node5 
#> "#983232" "#E4CACA" "#ffffff" "#CADFCA" "#328232" 
t_values <- z_values * 10 + 50
names(t_values) <- paste0("Node", 1:5)
colors <- values_to_colors_continuous(t_values, min = 20, max = 80, neutral_min = 45, neutral_max = 55)
print(colors)
#>     Node1     Node2     Node3     Node4     Node5 
#> "#983232" "#E4CACA" "#ffffff" "#CADFCA" "#328232"