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

Pierre Roudier pierre.roudier at gmail.com
Fri Jul 29 00:11:23 CEST 2011


Thanks Robert,

The trick is I'm using RColorBrewer, who does not provides this
posibility. But I coded a workaround, which basically turns an alpha
number between 0 an1 into a hex code, then insert that hex code in the
colours hex string. This is working.

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) ?

Cheers,

Pierre

2011/7/29 Robert Hijmans <r.hijmans at gmail.com>:
> Pierre,
>
> There are two ways. You can use the alpha argument in plot, or in a function
> that generates a vector of colors, see below. But note that this works in
> the previous and in the next version of raster, but in the current version
> only with 'oldstyle=TRUE'.
>
> >From ?slopeAspect
>
> library(raster)
> dem <- getData('alt', country='CHE')
> slas <- slopeAspect(dem)
> hill <- hillShade(slas[[1]], slas[[2]], 40, 270)
>
> plot(hill, col=grey(0:100/100), legend=FALSE, main='Switzerland')
> plot(dem, col=rainbow(25, alpha=0.35), add=TRUE)
>
> plot(hill, col=grey(0:100/100), legend=FALSE, main='Switzerland')
> plot(dem, col=rainbow(25), alpha=0.35, add=TRUE)
>
> # for the current version, use oldstyle=T
> plot(hill, col=grey(0:100/100), legend=FALSE, main='Switzerland')
> plot(dem, col=rainbow(25, alpha=0.35), add=TRUE, oldstyle=T)
>
> Robert
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Transparency-of-Raster-objects-tp6628801p6631467.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



-- 
Scientist
Landcare Research, New Zealand



More information about the R-sig-Geo mailing list