[R-sig-Geo] Mask a map using statistical significance

Thiago V. dos Santos thi_veloso at yahoo.com.br
Tue May 10 21:50:02 CEST 2016


Ruben, 

This is a tentative reproducible example using "real" spatial data, rather than the synthetic data I proposed in the original question.

(I should have thought of this example earlier, in order to spatially please Barry lol)

require(raster)
require(rasterVis)

# Scratch raster objects
data(volcano)
r1 <- raster(volcano)

over <- ifelse(volcano >=160 & volcano <=180, 1, NA) # This is the "mask" raster
r2 <- raster(over)

# And this is the key step:
# To convert the "mask" raster to spatial points
r.mask <- rasterToPoints(r2, spatial=TRUE)

# Plot
levelplot(r1, margin=F) +
layer(sp.points(r.mask, pch=20, cex=0.3, alpha=0.8))


It looks a little better now. To control the parameters of the points (such as color, size, type etc), documentation is available in ?sp.points . 
 Greetings,
 -- Thiago V. dos Santos

PhD student
Land and Atmospheric Science
University of Minnesota


On Monday, May 9, 2016 4:59 PM, Rubén Fernández-Casal <rubenfcasal at gmail.com> wrote:



I will appreciate instructions to reproduce this map...
Thanks...
Ruben FC

El 05/05/2016 00:06, "Thiago V. dos Santos via R-sig-Geo" <r-sig-geo at r-project.org> escribió: Thanks Barry and Arnaud (off-list) for the valuable hints. I ended up managing to use rasterVis' levelplot to produce the map I was looking for. The key step was to convert the raster I wanted to use as a mask to SpatialPoints, and then pass it as an additional layer to levelplot. The final map, produced using my actual data, can be visualized here: https://dl. dropboxusercontent.com/u/27700634/rainfall_trend.png. Stippling indicates regions exceeding the 95% statistical significance.



More information about the R-sig-Geo mailing list