[R-sig-Geo] image, SpatialGridDataFrame, transparency

Roger Bivand Roger.Bivand at nhh.no
Thu Aug 5 11:59:57 CEST 2010


On Thu, 5 Aug 2010, Patrick Giraudoux wrote:

> Hi,
>
> I was wondering if it is possible to manage color transparency with 
> image.SpatialGridDataFrame ? Eg to export png that could be imported into 
> Google Earth in the way indicated in Bivand et al. pp 97-98 (functions 
> kmlOverlay and GE_SpatialGrid of maptools). If yes how ?

NAs are set transparent by default (on output devices supporting 
transparency). Other values may be given an alpha of less than 1 - here a 
single value for all:

library(sp)
data(meuse.grid)
coordinates(meuse.grid) = c("x", "y")
gridded(meuse.grid) = TRUE
image(meuse.grid["dist"], col=heat.colors(12),
  main = "Distance to river Meuse")
image(meuse.grid["dist"], col=heat.colors(12, alpha=0.5),
  main = "Distance to river Meuse")

By setting the col= vector manually, it is possible to assign a different 
alpha value for each element, but it may be difficult to obtain a 
satisfactory visual impression consistently across output devices. See 
col2rgb() and rgb(). See also the colorspace package for a sophisticated 
treatment, and the use of hcl palettes, and the hsv() function. All of 
these can help in constructing a colour vector to pass to 
image.SpatialGridDataFrame().

Hope this helps,

Roger

>
> Patrick
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list