使用 ggmap 绘制城市各个部分的多个平移地图
Multiple panned maps of various sections of the city with ggmap
我可以达到 Plotting multiple maps with ggmap which is also possible with faceting as described in Kale & Wickham (2013) R Journal paper. But I would like to plot a multiple series of maps that pan around particular, zoomed areas of the city. This is sort of achievable if I look at the city coordinates obtained with geocode()
function and roughly figure out what I need to subtract or add from longitude/latitude on each side of pan the view. Such solution is far from ideal. Let me illustrate with an example (note: multiplot
function used from Cookbook For R).
library(ggmap)
library(RgoogleMaps)
#getting Bristol lat/long
BRS <- geocode("Bristol, UK")
#get the first (central) map from the coordinates
BristolMapCenter <- ggmap(get_map(c(lon=BRS$lon, lat=BRS$lat), zoom = 15))
#get the second map panned to the right by adding approx. 0.015 to longitude
BristolMapRight <- ggmap(get_map(c(lon=BRS$lon+0.015, lat=BRS$lat),zoom = 15))
#multiplot function
multiplot(BristolMapCenter, BristolMapRight, cols=2)
如您所见,这远非理想,因为总体而言(我不想要重叠,我想要 "lined up continuation"),如果不是说笨重的话,尤其是如果我想要更大的平移周边地区(比方说 9-12 张地图),为多个城市做,在上面绘制一些数据,我的生命中仍然有足够的时间在太阳上抓取 pint。所以我想知道是否有任何快速、流畅和自动的方法来获取基于特定中心坐标的平移地图?
从您的代码开始:
library(ggmap)
library(RgoogleMaps)
#getting Bristol lat/long
BRS <- geocode("Bristol, UK")
#get the first (central) map from the coordinates
BristolMapCenter <- ggmap(get_map(c(lon=BRS$lon, lat=BRS$lat), zoom = 15))
我们可以在此缩放级别提取地图覆盖的绝对范围:
z15width = sapply(BristolMapCenter$data, function(x) abs(diff(range(x))))
然后将它的倍数添加到您的 BRS 坐标中。
BristolRight = ggmap(get_map(c(lon = BRS$lon + z15width["lon"],
lat = BRS$lat), zoom = 15))
这些应该排列得很好。
multiplot(BristolMapCenter, BristolRight, cols = 2)
您可以在任何正交方向上移动 z15width
的整数倍,并且应该继续排列。当然,您会在不同的缩放比例下获得不同的宽度。您可以编写一个脚本来计算许多不同缩放值的宽度并将其存储在某处并稍后引用它。
我可以达到 Plotting multiple maps with ggmap which is also possible with faceting as described in Kale & Wickham (2013) R Journal paper. But I would like to plot a multiple series of maps that pan around particular, zoomed areas of the city. This is sort of achievable if I look at the city coordinates obtained with geocode()
function and roughly figure out what I need to subtract or add from longitude/latitude on each side of pan the view. Such solution is far from ideal. Let me illustrate with an example (note: multiplot
function used from Cookbook For R).
library(ggmap)
library(RgoogleMaps)
#getting Bristol lat/long
BRS <- geocode("Bristol, UK")
#get the first (central) map from the coordinates
BristolMapCenter <- ggmap(get_map(c(lon=BRS$lon, lat=BRS$lat), zoom = 15))
#get the second map panned to the right by adding approx. 0.015 to longitude
BristolMapRight <- ggmap(get_map(c(lon=BRS$lon+0.015, lat=BRS$lat),zoom = 15))
#multiplot function
multiplot(BristolMapCenter, BristolMapRight, cols=2)
如您所见,这远非理想,因为总体而言(我不想要重叠,我想要 "lined up continuation"),如果不是说笨重的话,尤其是如果我想要更大的平移周边地区(比方说 9-12 张地图),为多个城市做,在上面绘制一些数据,我的生命中仍然有足够的时间在太阳上抓取 pint。所以我想知道是否有任何快速、流畅和自动的方法来获取基于特定中心坐标的平移地图?
从您的代码开始:
library(ggmap)
library(RgoogleMaps)
#getting Bristol lat/long
BRS <- geocode("Bristol, UK")
#get the first (central) map from the coordinates
BristolMapCenter <- ggmap(get_map(c(lon=BRS$lon, lat=BRS$lat), zoom = 15))
我们可以在此缩放级别提取地图覆盖的绝对范围:
z15width = sapply(BristolMapCenter$data, function(x) abs(diff(range(x))))
然后将它的倍数添加到您的 BRS 坐标中。
BristolRight = ggmap(get_map(c(lon = BRS$lon + z15width["lon"],
lat = BRS$lat), zoom = 15))
这些应该排列得很好。
multiplot(BristolMapCenter, BristolRight, cols = 2)
您可以在任何正交方向上移动 z15width
的整数倍,并且应该继续排列。当然,您会在不同的缩放比例下获得不同的宽度。您可以编写一个脚本来计算许多不同缩放值的宽度并将其存储在某处并稍后引用它。