Skip to content

Instantly share code, notes, and snippets.

@avyfain
Created July 3, 2018 16:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avyfain/d51611e5b77a40e2bf5404ec6d9731db to your computer and use it in GitHub Desktop.
Save avyfain/d51611e5b77a40e2bf5404ec6d9731db to your computer and use it in GitHub Desktop.
rm(list=ls())
library(ggplot2)
library(ggmap)
library(plotKML)
cityMap <- qmap(location = 'san francisco', extent = 'device', zoom=12, source="google", maptype="terrain")
cityMap
kinds <- c('transport', 'walking', 'cycling')
colors <- c('#FF7400', '#1240AB', '#FFD300')
for (j in 1:length(kinds)) {
setwd(paste('<root>/moves_export/gpx/daily/', kinds[j], sep= ""))
files <- dir(pattern = "\\.gpx")
index <- c()
latitude <- c()
longitude <- c()
for (i in 1:length(files)) {
route <- readGPX(files[i])
location <- route$tracks[[1]][[1]]
if ( TRUE
# route$tracks[[1]][[1]]$time[1] > Sys.Date()-as.difftime(365, unit="days")
)
{
index <- c(index, rep(i, dim(location)[1]))
latitude <- c(latitude, location$lat)
longitude <- c(longitude, location$lon)
}
}
routes <- data.frame(cbind(index, latitude, longitude))
# Map the routes
cityMap <- cityMap + geom_path(aes(x = longitude, y = latitude, group = factor(index)),
colour=colors[j], data = routes, alpha=0.7)
}
cityMap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment