shading_raster: Create a Shading Raster with a Palette

Description Usage Arguments Examples

View source: R/shading_raster.R

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

1
2
3
4
5
6
7
8
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 nr, nc, middle. Suppose there is a matrix with nr rows and nc columns. A cell whose position in the matrix is designated by middle. Then, this cell gets the first color of palette, and other cells get shading colors according to their distances between them and middle. Method 2 to use this function is to use mat. The biggest cell gets the first color and other cells get shading colors.

nc

see nr.

middle

see nr. The parameter should be a length 2 vector designating the row number and column number of a cell.

palette

two or more colors used to make shading colors.

mat

see nr.

FUN

the default NULL makes the colors distributed in a linear way. However, FUN can be a single parameter function which transforms the numeric values, such as log, sqrt.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 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"))

plothelper documentation built on July 2, 2020, 4:03 a.m.