Thursday, February 19, 2015

Location History

Next week I’m giving a short presentation on graphics to the Cleveland R Group.  I needed geographic data for an example so I pulled my location history from Google.


The data ranges from Jan 1 2014 to Feb 11 2015.  Each record includes the date, time, longitude, and latitude of my location and records were typically taken 1 to 2 minutes apart.


Fig. 1:  Location tracking around west Cleveland, Ohio from Jan 2014 to Feb 2015.

It's interesting if you are familiar with west Cleveland but I decided not to label the map to keep some level of mystery.  I chose a few of my frequent locations and calculated distance between those places and my location at any given time.  Using this, here is a summary of my past 400 days:

  • 53% of my time was spent at home (~29% sleeping + ~24% relaxing)
  • 17% at work
  • 5.5% visiting my parents (Struthers)
  • 3% out of Ohio (DC, Chicago, Seattle, Texas)
  • 1% downtown Cleveland (mostly Playhouse Square)
  • 0.5% grocery shopping (Costco, Giant Eagle, Trader Joe's)
  • 4% driving
  • and 16% on other various unidentifiable adventures

So how much does the bitter cold keep me at home vs. doing anything else?  In my free time I am out of the house ~60% during months of reasonable weather vs. ~40% during the harsh winter months.  For every 3 times I leave the house in the summer, 1 of those times in the winter I just walk to the door and say "nope."


Fig. 2:  Percent of free time spent out of the house by month.  *Free time defined
as weekdays 6-8pm and weekends 9am-8pm.


I'll post my slides next week after the talk.  Until then I've included some of the code for the plots here down below.  My talk touch on customizing plots (labels, colors, shapes, etc.), ggplot2, and creating standard formats.  Bryan Lewis will be presenting htmlwidgets for R which I am eagerly anticipating.

EDIT: Here are the presentation files - http://files.meetup.com/3114872/CRUG_16_Graphics_20150225.zip


Partial R code for Fig. 1
bbX <- c(-82.15,-81.65); bbY <- c(41.35,41.55);  #boundaries for plot window
plot(x=loc$lon, y=loc$lat,
     xaxt='n', yaxt='n',  #remove plot axes ... add separately to customize
     ann=FALSE,  #remove axis labels and title
     xlim=bbX, ylim=bbY,  #set plot window
     pch='.', col=rgb(0,0,0,0.3))  #set point symbol and color (black transparent)
grid()
axis(1, line=-1, tick=FALSE, cex.axis=.65, padj=-0.2, col.axis='gray47')  #add x-axis
axis(2, line=-1, tick=FALSE, cex.axis=.65, las=1, hadj=1.2, col.axis='gray47')  #add y-axis

Partial R code for Fig. 2
plot(x=1:12, y=data$pct, ylim=c(0,1), type='n',
     xaxt='n', yaxt='n', xlab='', ylab='', main='% of free time spent out of the house*')
grid()
axis(1, at=1:12, labels=substr(data$month,1,1), line=-1, tick=FALSE, cex.axis=0.7)
axis(2, at=seq(0,1,0.2), labels=paste0(seq(0,1,0.2)*100,'%'), line=-1, tick=FALSE, cex.axis=0.7, las=1, hadj=1.2)
lines(x=1:12, y=data$pct, lwd=2)  #plot line on top of grid
lines(x=c(-1,13), y=c(0.499,0.499), lty=2, lwd=0.5, col=rgb(1,0,0,0.5))  #add reference line
text(1.35,0.535,'Avg=49.9%', col='red', cex=0.7)  #add reference line text

1 comment:

  1. WHY do I find this so exciting! I want to do it with my own location history! Nicely done Nick!!

    ReplyDelete