Helper function that converts numeric values to colors and returns a raster image. Useful for visualizing numeric matrices as color backgrounds.
Usage
as_colorraster(x, palette = hcl.colors(256), na.color = "white")Value
A raster object as produced by as.raster().
Details
Values in x are rescaled to the range of the palette using
scales::rescale(), and each value is mapped to a corresponding
color. If x is a matrix, the resulting raster preserves the same
dimensions.
Examples
# Convert the volcano matrix to a color raster
img <- as_colorraster(volcano)
plot(img)
# Use a different color palette
img <- as_colorraster(volcano, palette = terrain.colors(256))
plot(img)