getColors: Generate a three-color gradient palette

View source: R/getColors.R

getColorsR Documentation

Generate a three-color gradient palette

Description

Generate a three-color gradient palette

Usage

getColors(
  uniqueValues = c(-2:4)/10,
  binSize = 0.025,
  colorGradient = c("red", "white", "blue"),
  threshold = 0,
  type = "continuous"
)

Arguments

uniqueValues

input values (or vector with max/min)

binSize

size of increment between color gradations

colorGradient

vector with three colors that form the gradient

threshold

value of gradient transition. This value will be the middle color listed in 'colorGradient'

type

type of scale to be produced: 'continuous' (equally-sized intervals) or 'interval' (unequal intervals).

Value

A list with color codes and breaks

Examples

getColors(uniqueValues = range(-10:10), binSize = 5)
getColors(uniqueValues = range(-10:10), binSize = 3)
getColors(uniqueValues = range(0:100), binSize = 5, threshold = 50) # odd behavior
getColors(uniqueValues = range(0:99), binSize = 5, threshold = 50)
getColors(uniqueValues = range(-13:67)/100, binSize = 0.025)

### lop-sided categories with unequal sizes
getColors(uniqueValues = c(-365,-30, 0, 10, 30, 60, 365, 400, 700),
 type = 'interval', binSize = 5, threshold = 0)

f <- system.file("ex/elev.tif", package="terra") 
r <- rast(f)
plot(r)


cols <- getColors(uniqueValues = c(minmax(r)), binSize = 40, 
        threshold = mean(c(minmax(r))))
plot(r, breaks = cols$key, col = cols$colors)   

### example with five colors
cols <- getColors(uniqueValues = c(minmax(r)), binSize = 20, 
   threshold = mean(c(minmax(r))),
   colorGradient = c("red", "yellow", "white", "green", "blue"))
plot(r, col = cols$colors, type = 'continuous', breaks = cols$key)

cols <- getColors(uniqueValues = c(100, 195, 200, 205, 300, 350, 450, 550), 
        binSize = 40, # binSize argument is irrelevant if type = 'interval'
        threshold = 200, type = 'interval')
plot(r, breaks = cols$key, col = cols$colors)   


troyhill/EvergladesEBM documentation built on Nov. 19, 2023, 8:39 a.m.