1

I am producing some maps to include in a publication. However, I am not able to include a graticule on my plot such that it resembles that in the image shown below.

enter image description here

The image is projected but still has regular longitude and latitude gridlines. I am using the levelplot function for my mapping. Here is the code so far (insights from @Oscar Perpiñán):

library(raster)
library(rasterVis)
library(graticule)
rr <- getData('alt', country='CAN', mask=TRUE)

## Here is where the graticule routine starts
crs.longlat <- CRS("+init=epsg:4326")
ras = projectRaster(rr, crs = ('+proj=lcc +lat_1=49 +lat_2=77 +lat_0=63.390675 +lon_0=-91.86666666666666 +x_0=6200000 +y_0=3000000 +ellps=GRS80 +units=m +no_defs'))

prj <- CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")

extLL <- projectExtent(r, crs = crs.longlat)

lons <- pretty(c(xmin(extLL), xmax(extLL)))
lats <- pretty(c(ymin(extLL), ymax(extLL)))
## optionally, specify the extents of the meridians and parallels
## here we push them out a little on each side
xl <-  range(lons) + c(-0.4, 0.4)
yl <- range(lats) + c(-0.4, 0.4)
## build the lines with our precise locations and ranges
grat <- graticule(lons, lats, proj = prj,
                  xlim = xl, ylim = yl)
## Labels
labs <- graticule_labels(lons, lats,
                         xline = lons[2],
                         yline = lats[2],
                         proj = prj)
labsLon <- labs[labs$islon,]
labsLat <- labs[!labs$islon,]


levelplot(ras,margin=F,col.regions=col,contour=F,
          par.strip.text=list(cex=0),
          par.settings=list(panel.background=list(col="gray93"),axis.line=list(lwd=1.1), strip.border=list(lwd=1.1),
                            layout.heights=list(xlab.key.padding=-1.5)),
          cex=0.8, scales = list(x=list(draw=TRUE), y=list(draw=TRUE)),
          xlab=list(label=NULL,cex=1.5),
          ylab=list(label=NULL,cex=1.5))+ 
 ## and the graticule
 layer(sp.lines(grat)) +
 layer(sp.text(coordinates(labsLon),
               txt = parse(text = labsLon$lab),
               adj = c(1.1, -0.25),
               cex = 0.6)) +
 layer(sp.text(coordinates(labsLat),
               txt = parse(text = labsLat$lab),
               adj = c(-0.25, -0.25),
               cex = 0.6))

The problem is that the lonlat labels are not in the conventional format as in the image. I need to keep the projection of ras

Edzer provides a nice solution (curved text label demo) here add graticule to map via sp but I am unable to implement the approach using levelplot

How do I add nice gridlines to the map?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.