将分划添加到R中的投影贴图

将分划添加到R中的投影贴图,r,maps,raster,projection,gridlines,R,Maps,Raster,Projection,Gridlines,如何将分划添加到下面的地图ras: library(sf) library(raster) library(rgdal) library(rasterVis) library(graticule) ## Only needed for downloading a raster example rr <- getData('alt', country='CAN', mask=TRUE) ## Here is where the graticule routine starts crs.

如何将分划添加到下面的地图
ras

library(sf)
library(raster)
library(rgdal)
library(rasterVis)
library(graticule)

## Only needed for downloading a raster example

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=laea +lat_0=90 +lon_0=-100 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs'))

## Retrieve raster data
#r <- getRaster('temp', day = testDay, frames = 1)

## Here is where the graticule routine starts
prj <- CRS(projection(rr))
extLL <- projectExtent(ras, crs = crs.longlat)
extLL <- raster::extent(-141.1, -52.6, 41.6, 83.2)

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,]

library(colorRamps)
#brewer.pal(11,'RdYlBu')

col<-colorRampPalette(c("#0000FF", "#1919FF", "#3333FF", "#4C4CFF", 
                        "#6666FF", "#7F7FFF", "#9999FF", "#B2B2FF", "#FFCCCC", "#FFB2B2", "#FF9999", "#FF7F7F", 
                        "#FF6666", "#FF4C4C", "#FF3333", "#FF1A1A"))


## Display the raster
levelplot(ras,margin=F,col.regions=col)+
 ## 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))
库(sf)
图书馆(光栅)
图书馆(rgdal)
图书馆(拉斯特维斯)
图书馆(分划)
##仅用于下载光栅示例

rr您可以尝试使用package
tmap
,我相信它可以为光栅添加分划maps@TimSalabim好建议。非常感谢。然而,它并没有为我们提供可效仿的榜样。我将对这个软件包进行一些尝试和错误处理。rasterVis@OscarPerpiñán的FAQ页面中有一个例子,我看了这个例子。为什么不使用常规latlon值标记x轴和y轴?示例中的光栅使用不同的坐标投影系统: