[R-sig-Geo] Adding additional items to plot

Oscar Perpiñán Lamigueiro oscar.perpinan at gmail.com
Thu May 17 11:04:26 CEST 2012


Adam Sparks <adamhsparks at gmail.com> writes:

> Dear all,
> I'm attempting to produce some finished product maps using R and have been
> struggling with an issue.
>
> I want to use a hillshade object created from a DEM using the hillShade()
> function as a backdrop for my raster data that I'm presenting.
>
> Behind that I want to use lightsteelblue2 as the color where there is water.
>
> On top of this I want to plot the country outlines for the areas of
> interest.
>
> So in summary I have:
>  the first layer, blue for water
>  the second layer, hillshade DEM
>  the third layer, my raster data I'm presenting
>  the fourth layer, the country outline
>

Hello,

Try this approach using rasterVis and latticeExtra:

library(raster)
library(rasterVis)
library(maptools) ##for readShapeLines
library(latticeExtra)

## Get the data from gadm and data-vis
download.file('http://www.gadm.org/data/shp/ETH_adm.zip', '~/temp/ETH_adm.zip')
unzip('~/temp/ETH_adm.zip', exdir='~/temp')
download.file('http://www.diva-gis.org/data/msk_alt/ETH_msk_alt.zip', '~/temp/ETH_msk_alt.zip')
unzip('~/temp/ETH_msk_alt.zip', exdir='~/temp')
download.file('http://www.diva-gis.org/data/wat/ETH_wat.zip', '~/temp/ETH_wat.zip')
unzip('~/temp/ETH_wat.zip', exdir='~/temp')

## Read the files
proj <- CRS(' +proj=longlat +ellps=WGS84')
ethAdm <- readShapeLines('~/temp/ETH_adm1.shp', proj4string=proj)
ethWat <- readShapeLines('~/temp/ETH_water_lines_dcw.shp', proj4string=proj)
ethAlt <- raster('~/temp/ETH_msk_alt')

## and plot using the "+.trellis" and "layer" functions
## from latticeExtra
levelplot(ethAlt, par.settings=GrTheme) +
  layer(sp.lines(ethWat, col='blue', lwd=0.6)) +
  layer(sp.lines(ethAdm, col='black', lwd=0.7))

Best,

Oscar.

-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan



More information about the R-sig-Geo mailing list