Tôi đang sử dụng hàm tuyến đường ggmap để tính và hình dung hàng trăm tuyến đường sử dụng dữ liệu D.C. Capital Bikeshare. Tôi thành công có thể làm điều này với một vấn đề nhỏ, con đường tuyến đường không đi theo con đường, đặc biệt là những con đường cong (xem ảnh chụp màn hình bên dưới). Có cách nào để tweek mã của tôi cho tất cả các đường dẫn chi tiết hơn?Làm cách nào để lấy dữ liệu tuyến đường ggmap để đi theo đường dẫn
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")
thử với 'output = "tất cả"' bên 'con đường (từ = điểm bắt đầu, để = điểm dừng, chế độ = 'đi xe đạp', cấu trúc = "tuyến đường", đầu ra = "tất cả") ' – SymbolixAU
Điều đó gây ra do.call (rbind ... để ném lỗi này. function (..., row.name s = NULL, check.rows = FALSE, check.names = TRUE,: đối số ngụ ý số hàng khác nhau: 1, 0 –
Valzen của Mapzen là một dịch vụ web có thể cung cấp các tuyến từ điểm này sang điểm khác, kể cả GeoJSON của tuyến đường. https://mapzen.com/blog/valhalla-intro/. Gói GeoJSONio dường như có thể tiêu thụ điều đó. –