plot-overland-paris.ipynb
A GPS visualization of Paris for Overland data
This notebook requires you to use the Overland connection to get your GPS data from your iPhone into Open Humans.
This notebook then uses the GPS data to plot your personal movement history using R
.
For a start let's load our required packages:
With that out of the way we can access our Overland data from our Open Humans account. As the GPS records are can grow pretty large, each Year-Month
will get it's own file. The code below will randomly use one of your files.
If you want to adjust it to a specific month you can change overland-data
to something like overland-data-2018-12
following the overland-data-YYYY-MM
format. By default it uses 2019-06
as the data points
Now we can start downloading the data:
Now we can look into how our data looks like:
Now that we have our fitbit data stored in loc
we can start to work with that data. Much of this notebook is adapted code from Shirin Glander's excellent blogpost, which is based on Google Location History
data but the same principles apply for our Overland data.
Let's install the required ggmap
package and load some more data visualization tools:
And now we can plot that data:
This notebook requires you to use the Overland connection to get your GPS data from your iPhone into Open Humans.
This notebook then uses the GPS data to plot your personal movement history using R
.
For a start let's load our required packages:
library(httr)
library(jsonlite)
library(ggplot2)
library(devtools)
install.packages('ggmap')
library(purrr)
With that out of the way we can access our Overland data from our Open Humans account. As the GPS records are can grow pretty large, each Year-Month
will get it's own file. The code below will randomly use one of your files.
If you want to adjust it to a specific month you can change overland-data
to something like overland-data-2018-12
following the overland-data-YYYY-MM
format. By default it uses 2019-06
as the data points
month1 <- '2020-03'
Now we can start downloading the data:
access_token <- Sys.getenv("OH_ACCESS_TOKEN")
url <- paste("https://www.openhumans.org/api/direct-sharing/project/exchange-member/?access_token=",access_token,sep="")
resp <- GET(url)
user <- content(resp, "parsed")
user_data <- user$data
while (!is.null(user$`next`)) {
resp <- GET(user$`next`)
user <- content(resp, "parsed")
user_data <- append(user_data, user$data)
}
for (data_source in user_data){
if (grepl(paste('overland-data',month1,sep='-'), data_source$basename)){
print('read first month')
loc <- read.csv(url(data_source$download_url))
}
}
loc$velocity <- loc$speed
loc$date <- loc$timestamp
loc$lon <- loc$longitude
loc$lat <- loc$latitude
head(loc)
Now we can look into how our data looks like:
loc$velocity <- loc$speed
loc$date <- loc$timestamp
loc$lon <- loc$longitude
loc$lat <- loc$latitude
head(loc)
Now that we have our fitbit data stored in loc
we can start to work with that data. Much of this notebook is adapted code from Shirin Glander's excellent blogpost, which is based on Google Location History
data but the same principles apply for our Overland data.
Let's install the required ggmap
package and load some more data visualization tools:
library(lubridate)
library(zoo)
# set up plotting theme
library(ggplot2)
library(ggmap)
my_theme <- function(base_size = 12, base_family = "sans"){
theme_grey(base_size = base_size, base_family = base_family) +
theme(
axis.text = element_text(size = 12),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1),
axis.title = element_text(size = 14),
panel.grid.major = element_line(color = "grey"),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill = "aliceblue"),
strip.background = element_rect(fill = "lightgrey", color = "grey", size = 1),
strip.text = element_text(face = "bold", size = 12, color = "navy"),
legend.position = "right",
legend.background = element_blank(),
panel.margin = unit(.5, "lines"),
panel.border = element_rect(color = "grey", fill = NA, size = 0.5)
)
}
loc$weekday <- wday(loc$timestamp)
loc$weekend <- loc$weekday %in% c('Sunday','Saturday')
loc$weekend <- ifelse(loc$weekend, 'weekend', 'weekday')
loc$hour <- hour(loc$timestamp)
boundary_west=2.3
boundary_east=2.40 # for those I wouldn't have needed to ask Google thanks to the Prime Meridian in Greenwich :D
boundary_south=48.815 # 3
boundary_north=48.9
my_map <- get_stamenmap(bbox=c(boundary_west,
boundary_south,
boundary_east,
boundary_north),zoom=13,maptype='toner',force=TRUE)
And now we can plot that data:
library(repr)
options(repr.plot.width=10, repr.plot.height=10)
ggmap(my_map) +
geom_point(data = subset(loc, loc$motion %in% c('stationary', 'walking')),
aes(x = lon,
y = lat), alpha=0.6, size=0.5,color='red') +
theme(legend.position = "right") + facet_grid(. ~ motion)