ggmap :: get_map不允许我的地图角落的确切规格?

use*_*534 12 r ggmap

我正在使用R包ggmap.

?get_map 说:

location:地址,经度/纬度对(按此顺序),或左/下/右/顶部边界框

我的代码:

library(ggmap)
library(mapproj)

lat_bottom = 52.33  # bottom latitude of Berlin
lat_top    = 52.5   # top latitude of Berlin
lon_left   = 13.0   # left longitude of Berlin
lon_rigth  = 13.95  # right longitude of Berlin

mymap <- get_map(location = c(lon_left,lat_bottom,lon_rigth,lat_top),
source="google")
ggmap(mymap)
Run Code Online (Sandbox Code Playgroud)

为什么它会给我一个警告:

警告:给谷歌的边界框 - 空间范围只是近似值.将边界框转换为中心/缩放规范.(实验)

这是否意味着我无法创建具有这些精确角落的地图?

根据以下建议我尝试了这个:

lat_bottom = 52.33  # bottom latitude of Berlin
lat_top    = 52.68   # top latitude of Berlin
lon_left   = 13.08   # left longitude of Berlin
lon_rigth  = 13.77  # right longitude of Berlin

mylon = c(lon_left,lon_rigth)
mylat = c(lat_bottom,lat_top)

mymap <- get_map(location = c(lon = mean(mylon), lat = mean(mylat)),
               maptype = "roadmap", source = "google", zoom=11) # using zoom
ggmap(mymap)
foo<-ggmap(mymap)+
  scale_x_continuous(limits = c(lon_left,lon_right), expand = c(0, 0)) +
  scale_y_continuous(limits = c(lat_bottom,lat_top), expand = c(0, 0))
foo
Run Code Online (Sandbox Code Playgroud)

看起来不错.但是当我拿出其他坐标(那些彼此更接近的坐标)时,例如下面那些 - 那么地图看起来很奇怪 - 它有点在灰色背景上向左移动......

lat_bottom = 52.35  # new bottom
lat_top    = 52.50  # new top
lon_left   = 13.2   # new left
lon_rigth  = 13.5   # new right
Run Code Online (Sandbox Code Playgroud)

Jaa*_*aap 12

如果您想使用边界,最好使用OpenStreetMap而不是GoogleMaps.设置GoogleMaps的边界ggmap不起作用.相反,它将估计中心点.

您可以通过source = "osm"get_map通话中加入来指定来源.

附:

mymap <- get_map(location = c(13.2,52.35,13.5,52.50), source = "osm")

ggmap(mymap)
Run Code Online (Sandbox Code Playgroud)

你得到:

在此输入图像描述