2

我正在尝试用ggmap. 该地区的中心在纬度附近的某个地方。80 朗。0,不幸的是只显示了灰色背景和经纬度轴。我试图绘制不同的区域,我的代码似乎在每个位置都有效,除了纬度以外的区域。73.6。这是我的代码示例:

library(ggmap)
library(mapproj)
location <- get_map(location = c(lon = 0, lat = 80), zoom = 4, maptype = "hybrid")
ggmap(location)

那么有谁知道,为什么ggmap无法绘制这个位置?

4

1 回答 1

3

我遇到了同样的问题(在尝试绘制 Antartica 时)并且为了解决它,我求助于ggplot,但依赖于ggmap包中的几个函数。正如@Henrik 的链接所暗示的那样,地图投影似乎是问题所在。

整个想法和代码由 David Kahle 提供

您可以采取以下措施使其适用于您的案例:

location <- get_map(location = c(lon = 0, lat = 80), zoom = 4, maptype = "hybrid")

#Create a small data frame to pass to ggplot
fourCorners <- expand.grid(
  lon = as.numeric(attr(location, "bb")[, c("ll.lon", "ur.lon")]), 
  lat = as.numeric(attr(location, "bb")[, c("ll.lat", "ur.lat")])
  )
# The inset_raster function needs 4 data coordinates. Pull it out of your "location" that you got via get_map
xmin <- attr(location, "bb")$ll.lon
xmax <- attr(location, "bb")$ur.lon
ymin <- attr(location, "bb")$ll.lat
ymax <- attr(location, "bb")$ur.lat

# Now you are ready to plot it
mp <- ggplot(fourCorners, aes(x = lon, y = lat) ) + 
 inset_raster(location, xmin, xmax, ymin, ymax)            
mp

它为您提供了以 (Longitude=0, lat=80) 为中心的“混合”地图

在此处输入图像描述

于 2013-11-23T00:02:59.560 回答