r - 在 R map 中包含比例和坐标

标签 r maps geospatial

我正在使用以下代码在 R 中绘制 map :

library(maps)
library(mapdata)

map('worldHires',c('UK'),
    xlim=c(-10,-1),
    ylim=c(56,59.5))  
points(-5.65,56.7233,col=2,pch=18)

导致

enter image description here

如何在 map 上添加比例尺以及在 map 周围显示纬度和经度的方框?类似于:

enter image description here

最佳答案

maps 包还有一个函数 map.axesmap.scales

library(maps)
library(mapdata)

map('worldHires',c('UK'), xlim=c(-10,-1),
    ylim=c(56,59.5))

points(-5.65,56.7233,col=2,pch=18)
map.axes()
map.scale()

给你

enter image description here

编辑1

如果您查看 map.axes 的代码,您会发现它只是调用了 axisbox。一种方法是手动执行此操作并调整标签。

library(maps)
library(mapdata)

m <- map('worldHires',c('UK'), xlim=c(-10,-1),
         ylim=c(56,59.5), mar=c(4, 4, 4, 4))

points(-5.65,56.7233,col=2,pch=18)

xat <- pretty(m$range[1:2])
xlab <- paste0(xat, " E")

yat <- pretty(m$range[3:4])
ylab <- paste0(yat, " N")

box()
axis(1, at=xat, labels=xlab)
axis(2, las=TRUE, at=yat, labels=ylab)
axis(3, at=xat, labels=xlab)
axis(4, las=TRUE, at=yat, labels=ylab)
map.scale(y=59)

这将为您提供具有调整标签的相同图片 enter image description here

编辑2:

或者按照@Pascal 的建议使用raster::degreeLabels* 函数。

library(maps)
library(mapdata)
library(raster)

m <- map('worldHires',c('UK'), xlim=c(-10,-1),
         ylim=c(56,59.5), mar=c(4, 4, 4, 4))

points(-5.65,56.7233,col=2,pch=18)

xat <- pretty(m$range[1:2])
xlab <- parse(text=degreeLabelsEW(xat))

yat <- pretty(m$range[3:4])
ylab <- parse(text=degreeLabelsNS(yat))


box()
axis(1, at=xat, labels=xlab)
axis(2, las=TRUE, at=yat, labels=ylab)
axis(3, at=xat, labels=xlab)
axis(4, las=TRUE, at=yat, labels=ylab)

map.scale(y=59)

enter image description here

关于r - 在 R map 中包含比例和坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26114962/

相关文章:

从一长串变量中重新编码

r - 如何在 R 中正确地将 map 添加到光栅图像

mysql - MySQL GLength 方法返回的单位是什么?

javascript - 传单:panTo Web 墨卡托坐标 (EPSG 3857)

swift - 反向地理编码位置 : more accuracy than range

performance - 防止请求垃圾邮件

r - 将经度和纬度与 R 中的国家/地区相匹配

r - 根据另一个列表对一个列表进行子集化,然后查找最大值的位置

string - 将字符添加到数据集中的字符串子集

android - "Failed to load map. Could not contact Google servers."