raster_alpha: Combine a Matrix of Colors and a Matrix of Alpha Values

Description Usage Arguments Examples

View source: R/raster_alpha.R

Description

The function is a wrapper of scales::alpha. While the latter only works on vectors, the former can combine a matrix of colors and a matrix of alpha values as long as the two have the same numbers of rows and columns.

Usage

1
raster_alpha(color, alpha, result = "raster", res = 144)

Arguments

color

a matrix of colors, a raster or an image read into R by magick::image_read.

alpha

either a single value (e.g., 0.4) or a matrix of alpha values. The matrix should have the same numbers of rows and columns as color.

result

if it is "raster", the result will be a matrix which can be used by annotation_raster (default), if it is "magick", the result is a magick image.

res

the res parameter used by magick::image_graph when result is "magick". Default is 144.

Examples

1
2
3
4
5
6
7
8
# A color matrix
co=c("red", "yellow", "green", "blue")
co=rbind(co, co, co)
# An alpha matrix
alp=c(1, 0.6, 0.3, 0.1)
alp=rbind(alp, alp, alp)
# Now combine the two
result=raster_alpha(co, alp)

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