getColors | R Documentation |
Generate a three-color gradient palette
getColors(
uniqueValues = c(-2:4)/10,
binSize = 0.025,
colorGradient = c("red", "white", "blue"),
threshold = 0,
type = "continuous"
)
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). |
A list with color codes and breaks
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.