[R-sig-Geo] Transparency of Raster* objects

Robert Hijmans r.hijmans at gmail.com
Fri Jul 29 10:50:49 CEST 2011


Pierre, 

> The trick is I'm using RColorBrewer, who does not provides this 
> posibility. 

No, but the alpha argument to plot (with a Raster* object) does:

r <- raster(system.file("external/test.grd", package="raster"))
library(RColorBrewer)
col <- brewer.pal(9, 'GnBu')
plot(r, col=col, alpha=0.3)

> However, what I'm still stuck at using a variable transparency in 
> space, eg in the meuse.grid dataset, how to make transparency a 
> function of the distance to the river (the dist attribute) ? 

I do not know; the below is ugly, but perhaps it provides some ideas:



library(raster)

data(meuse.grid)
coordinates(meuse.grid) <- ~x+y
proj4string(meuse.grid) <- CRS("+init=epsg:28992")
gridded(meuse.grid) <- TRUE
data(meuse.riv)
meuse.sr =
SpatialPolygons(list(Polygons(list(Polygon(meuse.riv)),"meuse.riv")))

r <- raster(meuse.grid, 'dist')
riv <- rasterize(meuse.sr, r)

d <- distance(riv)
d[d > 1000] <- 1000
d <- 254 * d/1000

a <- c(0:9, LETTERS[1:6])

bw <- paste("#000000", rep(a, each=16), rep(a, times=16), sep='')
plot(r)
plot(d, col=bw, add=T)

x11()
ter <- paste(substr(terrain.colors(254), 1, 7), rep(a, each=16), rep(a,
times=16), sep='')
plot(r, col=gray(1:255/255))
plot(d, col=ter, add=T)

Best, Robert

--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Transparency-of-Raster-objects-tp6628801p6632801.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list