Convert RGB maps to semi-transparent
Stamen-toner maps are 3-layer RGB rasters, which are converted to single-layer rasters with indexed colours with whites becoming transparent.
tonerToTrans(x, pattern="(red|green|blue)$", power = 0.5, col='black', threshold=Inf, mostCommon=1)
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 transparencycol
: colour for resulting mapthreshold
: colours above this value are transparentmostCommon
: integer vector, the most common colours are converted to transparentA SpatRast
with indexed colours
Patrick Brown
openmap
origMap = openmap( c(-11, 9), path='cartodb-nolabels', buffer=2, verbose=TRUE ) oldpar= map.new(origMap, bg='green') plot(origMap, add=TRUE) transMap = tonerToTrans(origMap, mostCommon=1) names(transMap) map.new(transMap, bg='green') plot(transMap, add=TRUE) par(oldpar)
Useful links