{osmdata}でエトセトラ(3/3) 道路の方角ごとに塗り分け
{osmdata}
で取得した道路ネットワークで遊ぶ第3回。最後は道路の方角ごとに色を分けて地図に描画してみる。
カラーパレットの作成
{RcolorBrewer}
のカラーパレットSpectral
を元に以下の条件でカラーパレットを作成する。
- 0度、90度、180度に近ければ黄色
- 45度に近ければ青
- 135度に近ければ赤
colors <- c( RColorBrewer::brewer.pal(11, "Spectral")[6:11], rev(RColorBrewer::brewer.pal(11, "Spectral")[7:10]), rev(RColorBrewer::brewer.pal(11, "Spectral")[1:6]), RColorBrewer::brewer.pal(11, "Spectral")[2:6] ) colors [1] "#FFFFBF" "#E6F598" "#ABDDA4" "#66C2A5" "#3288BD" "#5E4FA2" "#3288BD" "#66C2A5" "#ABDDA4" [10] "#E6F598" "#FFFFBF" "#FEE08B" "#FDAE61" "#F46D43" "#D53E4F" "#9E0142" "#D53E4F" "#F46D43" [19] "#FDAE61" "#FEE08B" "#FFFFBF"
実際の色を確認してみる。
image(seq_along(colors), 1, as.matrix(seq_along(colors)), col = colors, xlab = "Colors", ylab = "", xaxt = "n", yaxt = "n")
45度と135度を同じ色にして{viridis}
のカラーパレットを使用してみると以下のようになる。
colors <- c( viridis::viridis(n = 45, direction = -1), viridis::viridis(n = 45)) %>% rep(2) image(seq_along(colors), 1, as.matrix(seq_along(colors)), col = colors, xlab = "Colors", ylab = "", xaxt = "n", yaxt = "n")
道路ネットワークの描画
あとは{leaflet}
で地図に描画するだけ。
pal <- leaflet::colorNumeric(palette = colors, domain = 0:180) ways.bearing %>% leaflet::leaflet(options = leaflet::leafletOptions(zoomControl = FALSE)) %>% leaflet::addProviderTiles(leaflet::providers$CartoDB.DarkMatter) %>% leaflet::addPolylines(color = ~pal(bearing %% 180), weight = 1, opacity = 1.0) %>% leaflet::addPolygons(data = city, fillColor = "Transparent", color = "white", weight = 2) %>% leaflet::addLegend("bottomright", pal = pal, values = ~(bearing %% 180), title = "Bearing")
豊洲やお台場など埋め立てられてできた土地の道路ネットワークは格子状とはいえ45度傾いて見える。
{viridis}
で描画してみると次のような感じに。
横浜は綺麗。
京都はほぼ一色w
OpenStreetMapの道路ネットワークで色々遊ぶことができた。道路ネットワークを可視化することで街のでき方がわかるの興味深い。{osmdata}
と{ggplot2}
で地図をアートにする方もいるので是非チャレンジしてみたい。
Finally finished a #quarantine project with @jennawneal, using #rstats #osmdata and #ggplot2 to create maps of cities (with blue rivers) & wine regions (with purple vineyards) we've visited.
— Zachary Neal (@zpneal) 2020年8月28日
Can you identify them from this fuzzy photo?
Code and material in the comments. 👇 pic.twitter.com/9Nt8rssyAu