Created
July 3, 2018 16:23
-
-
Save avyfain/d51611e5b77a40e2bf5404ec6d9731db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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