shading_raster {plothelper} | R Documentation |
Create a Shading Raster with a Palette
Description
The function is a simple wrapper of
scales::col_numeric
.
The function creates a matrix of colors
that can be used to draw a shading rectangle.
There are 2 ways to use the function, see
the following parameters.
Usage
shading_raster(
nr = NULL,
nc = NULL,
middle = NULL,
palette = c("blue", "red"),
mat = NULL,
FUN = NULL
)
Arguments
nr |
method 1 to use
this function is to use |
nc |
see |
middle |
see |
palette |
two or more colors used to make shading colors. |
mat |
see |
FUN |
the default NULL makes the colors
distributed in a linear way. However, |
Examples
# Use method 1.
r=shading_raster(nr=31, nc=60, middle=c(10, 55),
palette=c("darkorange", "red", "purple"))
ggplot()+xlim(0, 8)+ylim(0, 6)+
annotation_raster(r, xmin=-Inf, xmax=Inf,
ymin=-Inf, ymax=Inf, interpolate=TRUE)
# Use method 2.
r=matrix(c(
1, 2, 3, 4, 5, 6, 7, 8,
1, 2, 3, 4, 5, 6, 7, 8,
1, 1, 1, 1, 1, 1, 1, 1),
nrow=3, byrow=TRUE)
r=shading_raster(mat=r, palette=c("green", "blue"))