0

I'm using R for a climate research study and I'm trying to draw a map with a digital elevation model as base layer. I want to plot another (smaller) raster (containing climate information) on top of this dem, obviously with different colors. The result I'm after is like this: http://climate.calcommons.org/sites/default/files/basic/modelmaps.png I'm trying to use ggplot2, but it only allows for 1 fill color scale, so no luck. I've also tried the raster package, but with no success. Any tips?

demonplus
  • 5,613
  • 12
  • 49
  • 68
user975296
  • 531
  • 1
  • 4
  • 3

1 Answers1

1

My solution uses the +.trellis mechanism implemented in the package latticeExtra combined with the levelplot function of the rasterVis package:

library(raster)
library(rasterVis)

## Create raster objects
f <- system.file("external/test.grd", package="raster")
r <- raster(f)
r0 <- init(r, fun = rnorm)

## Produce graphics with a different palette
p0 <- levelplot(r0, par.settings = GrTheme)
p1 <- levelplot(r, par.settings = magmaTheme)

The results are displayed together using + (the first plot sets the color scale):

p0 + p1

overlay

You should use as.layer to change the color scale:

p1 + as.layer(p0, under = TRUE)

overlay 2

Oscar Perpiñán
  • 4,491
  • 17
  • 28