| 1 |
# rescaling functions needed for ggplot continuous color scales |
| 2 |
# the scales dependency is automatically satisfied when ggplot2 is installed |
| 3 |
|
| 4 |
# returns a rescaling function that scales to a target range |
| 5 |
to_rescaler <- function(begin = 0, end = 1) { |
| 6 |
function(x, to = c(begin, end), from = range(x, na.rm = TRUE)) { |
| 7 |
scales::rescale(x, to, from) |
| 8 |
} |
| 9 |
} |
| 10 |
|
| 11 |
# returns a rescaling function that scales to a target midpoint |
| 12 |
mid_rescaler <- function(mid) { |
| 13 |
function(x, to = c(0, 1), from = range(x, na.rm = TRUE)) { |
| 14 |
scales::rescale_mid(x, to, from, mid) |
| 15 |
} |
| 16 |
} |