包括R map中的比例和坐标

时间:2014-09-30 07:20:02

标签: r maps geospatial

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

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

如何向地图添加比例以及显示纬度和经度的围绕它的框?类似于:

enter image description here

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:3)

根据rengis回答:

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

map('worldHires',c('UK'), xlim=c(-10,-1), ylim=c(56,59.5))
points(-5.65,56.7233,col=2,pch=18)
maps::map.scale(-9.5,56.2)
axis(1, at = seq(-10,-2,2), parse(text=degreeLabelsEW(seq(-10,-2,2))))
axis(2, at = seq(56,59,1), parse(text=degreeLabelsNS(seq(56,59,1))))
north.arrow(-8.5, 59, 0.1, "N")
box()

enter image description here