Часто возникает необходимость выпускать стильные карты для включения в публикации.
Как можно включить спроецированные координаты сетки в карту, сгенерированную предпочтительно с помощью levelplot
, чтобы она выглядела так, как на карте, показанной здесь:
Я привожу образцы данных (для Канады) ниже для воспроизводимости. Типичная проекция для Канады — dat = projectRaster(dem, crs = ('+proj=stere +lat_0=90 +lat_ts=60 +lon_0=-110 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs'))
, а SpTransform
можно использовать для преобразования граничных линий (can1
).
require(colorRamps)
require(raster)
require(rasterVis)
require(mapproj)
library(raster)
library(proj4)
# Get province borders and project it to same CRS than raster
can1 <- getData('GADM', country="CAN", level=1)
getData('ISO3') # country name
dem=getData('alt', country='CAN', mask=TRUE)
require( colorRamps )
my.at <- unique(round(seq(ceiling(5800), floor(1), length.out = 51),0))#at: numeric vector specifying where the colors change. must be of length 1 more than the col vector.
col<-colorRampPalette(c("#d9d9d9", "#bdbdbd", "#969696", "#737373", "#525252", "#252525", "#000000"))
levelplot(dem,maxpixel=ncell(dem),panel=panel.levelplot.raster,names.attr=names(dem),
interpolate=F,margin=FALSE,xlab=list(label="Longitude",cex=1.5),yscale.components = yscale.raster.subticks,
xscale.components = xscale.raster.subticks,
ylab=list(label="Latitude",cex=1.5),
par.strip.text=list(cex=1),xlim=c(-158, -48.99485),
ylim=c(38.00513, 85),col.regions=col,at = seq(0, 5800,100),
colorkey = list(space = "bottom", labels = list(at = seq(0, 5800,800), rot=0,cex=1.1,font=6,fontface=1,
labels =c("0", "800", "1600", "2400", "3200", "4000", "4800", "5600")),
height=0.99,width=1.8,tck = c(0,0)),
par.settings=list(panel.background=list(col="white"),axis.line=list(lwd=1.9), strip.border=list(lwd=1.9),layout.heights=list(xlab.key.padding=-0.2)),
cex=0.8, scales = list(x=list(draw=TRUE,cex=1.2), y=list(draw=TRUE,cex=1.2)))+
layer(sp.polygons(can1,lwd=0.5,col="gray40"))