我喜欢ggmap在特定区域绘制街道.我通过立交桥api从osm获取数据.它适用于大多数街道geom_path.然而,一些街道搞砸了.任何提示都表示赞赏.
请查看http://overpass-turbo.eu/获取所需的输出.您可以在下面的R代码中找到查询.
library(httr)
library(tidyverse)
#> ?? Attaching packages ??????????????????????????????????????????????????????????????????????????????????????????? tidyverse 1.2.1 ??
#> ? ggplot2 2.2.1 ? purrr 0.2.4
#> ? tibble 1.4.2 ? dplyr 0.7.4
#> ? tidyr 0.8.0 ? stringr 1.3.0
#> ? readr 1.1.1 ? forcats 0.3.0
#> ?? Conflicts ?????????????????????????????????????????????????????????????????????????????????????????????? tidyverse_conflicts() ??
#> ? dplyr::filter() masks stats::filter()
#> ? dplyr::lag() masks stats::lag()
library(ggmap)
library(rlist)
# Get data from overpass api
query <- paste('[out:json];',
'(way["highway"~"primary|residential"](53.5970, 9.9010, 53.6050, 9.9080););',
'(._;>;);',
'out body;') …Run Code Online (Sandbox Code Playgroud) 我喜欢在地图上的多个位置绘制等时线,这样我就可以直观地找到从任意城镇到最近位置的旅行时间。它应该看起来像一个核密度二维图:
library(purrr)
library(ggmap)
locations <- tibble::tribble(
~city, ~lon, ~lat,
"Hamburg", 9.992246, 53.550354,
"Berlin", 13.408163, 52.518527,
"Rostock", 12.140776, 54.088581
)
data <- map2_dfr(locations$lon, locations$lat, ~ data.frame(lon = rnorm(10000, .x, 0.8),
lat = rnorm(10000, .y, 0.7)))
ger <- c(left = min(locations$lon) - 1, bottom = min(locations$lat) - 1,
right = max(locations$lon) + 1, top = max(locations$lat) + 1)
get_stamenmap(ger, zoom = 7, maptype = "toner-lite") %>%
ggmap() +
stat_density_2d(data = data, aes(x= lon, y = lat, fill = ..level.., alpha = …Run Code Online (Sandbox Code Playgroud)