How can I recreate the default color palette for the raster package in R? I cannot find details on the default raster plotting color scheme in online documentation. Thanks!
If we review the source code for the custom plot method for objects of type Raster, we will see that line 12 shows:
col <- rev(terrain.colors(255))
If you type terrain.colors you will see the code used to calculate the colors:
terrain.colors
function (n, alpha = 1, rev = FALSE)
{
if ((n <- as.integer(n[1L])) > 0) {
k <- n%/%2
h <- c(4/12, 2/12, 0/12)
s <- c(1, 1, 0)
v <- c(0.65, 0.9, 0.95)
cols <- c(hsv(h = seq.int(h[1L], h[2L], length.out = k),
s = seq.int(s[1L], s[2L], length.out = k), v = seq.int(v[1L],
v[2L], length.out = k), alpha = alpha), hsv(h = seq.int(h[2L],
h[3L], length.out = n - k + 1)[-1L], s = seq.int(s[2L],
s[3L], length.out = n - k + 1)[-1L], v = seq.int(v[2L],
v[3L], length.out = n - k + 1)[-1L], alpha = alpha))
if (rev)
cols <- rev(cols)
cols
}
else character()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With