9
私は、D.C. Capital Bikeshareデータを使って何百もの経路を計算し、視覚化するためにggmap経路関数を使用しています。 1つのマイナーな問題でこれを成功させることができました。ルートパスは道路、特にカーブした道路に従いません(下記のスクリーンショットを参照)。より詳細なパスのために私のコードをすべてtweekする方法はありますか?道路経路に従うようにggmap経路データを取得するには
library(tidyverse)
library(ggmap)
# Example dataset
feb_14 <- read.csv('https://raw.githubusercontent.com/smitty1788/Personal-Website/master/dl/CaBi_Feb_2017.csv', stringsAsFactors = FALSE)
# Subset first 300 rows, keep start and end Lat/Long strings
start<-c(feb_14[1:300, 14])
dest<-c(feb_14[1:300, 15])
# df of individual routes
routes <- tibble(
start,
dest)
# Function to calculate route
calculationroute <- function(startingpoint, stoppoint) {
route(from = startingpoint,
to = stoppoint,
mode = 'bicycling',
structure = "route")}
# Calculate route path for all individual trips
calculatedroutes <- mapply(calculationroute,
startingpoint = routes$start,
stoppoint = routes$dest,
SIMPLIFY = FALSE)
# Unlist and merge in single dataframe
do.call(rbind.data.frame, lapply(names(calculatedroutes), function(x) {
cbind.data.frame(route=x, calculatedroutes[[x]], stringsAsFactors=FALSE)
})) -> long_routes
# create map with routes
basicmap <- get_map(location = 'washingtondc',
zoom = 13,
maptype = "toner-background",
source = "google",
color = "bw")
basicmap <- ggmap(basicmap)
basicmap + geom_path(data=long_routes,
aes(x=lon, y=lat, group=route), color = "red",
size=1, alpha = .4, lineend = "round")
試しました to = stoppoint、 mode = 'bicycling'、 構造体: "route"、出力= "all") ' – SymbolixAU
これにより、do.call(rbind ...がこのエラーをスローします。 function(...、row.name = 0、check.rows = FALSE、check.names = TRUE、: 引数の行数が異なることを暗示しています。 –
MapzenのValhallaは、ルートのGeoJSONを含むポイントツーポイントのルートを提供できるWebサービスです。 https://mapzen.com/blog/valhalla-intro/。 GeoJSONioパッケージは明らかにそれを消費する可能性があります。 –