Learn R Programming

mapmisc (version 1.7.0)

tonerToTrans: Convert RGB maps to semi-transparent

Description

Stamen-toner maps are 3-layer RGB rasters, which are converted to single-layer rasters with indexed colours with whites becoming transparent.

Usage

tonerToTrans(x,  pattern="(red|green|blue)$", power = 0.5, col='black',  threshold=Inf)
rgbtToIndex(x,  pattern="(red|green|blue|trans)$")

Arguments

x

A RasterStack with RGB colours, such as from openmap with path='stamen-toner'

pattern

string passed to grep to find RGB layers.

power

Values below 1 increase opacity, above 1 increases transparency

col

colour for resulting map

threshold

colours above this value are transparent

Value

A RasterLayer with indexed colours

Details

The difference between these functions is that tonerToTrans converts white to transparent, whereas rgbtToIndex uses the transparency layer. The former is intended for 'stamen-toner' maps.

See Also

openmap

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
	rgbMap = openmap(c(0,10), zoom=3, path='stamen-toner')
	names(rgbMap)
	plotRGB(rgbMap)
	
	transMap = tonerToTrans(rgbMap, col='blue')
	names(transMap)
	par(bg='red')
	plot(transMap)

	rgbMap[['stamen.tonerTrans']] = 255-rgbMap[['stamen.tonerRed']]
	rgbtMap = rgbtToIndex(rgbMap)
	plot(rgbtMap)
# }

Run the code above in your browser using DataLab