我正在尝试使用 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
无法绘制这个位置吗?
最佳答案
我也遇到了同样的问题(当试图绘制南极洲时),为了解决这个问题,我求助于 ggplot
,但依赖 ggmap
中的几个函数包裹。
正如@Henrik 的链接所示, map 投影似乎是问题所在。
整个想法和代码由 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
这将为您提供以(经度=0,纬度=80)为中心的“混合” map
关于r - ggmap 无法绘制特定区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20143851/