# Special thanks for insights from flowingdata.com regarding this.

library

library

library

library

<-

5

# Usage: Place this script in the directory containing your runkeeper data. You can run from terminal using 'Rscript map_runkeeper.R', or

# set your working directory to the location and run within RStudio (use setwd("~/location/of/runkeeper/data")).

# See below on how to set the number of clusters.

# GPX files downloaded from Runkeeper

<-

dir

=

"\\.gpx"

# Generate vectors for data frame

<-

c

<-

c

<-

c

<-

c

<-

1

# Set up Counter

#

for

1

:

length

<-

readGPX

# Treat interrupted GPS paths as seperate routes (useful if you occasionally stop running..walk for a bit, and start again like I do.)

for

$

<-

+

1

<-

<-

c

rep

dim

<-

c

rep

dim

<-

c

$

<-

c

$

<-

data.frame

cbind

# Because the routes dataframe takes a while to generate for some folks - save it!

save

=

"routes.Rdata"

# Use to load as needed.

load

"routes.Rdata"

# Fix data types

$

<-

as.character

$

$

<-

as.numeric

levels

$

$

$

<-

as.numeric

levels

$

$

<-

transform

=

as.numeric

# Load Meta Data

<-

read.csv

"cardioActivities.csv"

=

FALSE

<-

rename

c

"GPX.File"

=

"file"

# Bind routes

<-

left_join

=

"file"

%.%

arrange

# Use this function specify activity color if you have multiple activities.

<-

function

if

==

"Cycling"

=

"#00000060"

if

==

"Hiking"

=

"#00000060"

=

"#0080ff60"

# Identify clusters of points, which will correspond to locations you have run. For example,

# I have run in Boston, Iowa City, Chicago, and a few other cities. You will want to set the minimum krange

# to the number of cities you have run in (5 in my case).

<-

pamk

c

"latitude"

"longitude"

=

:

20

=

=

$

$

# Plot Everything

for

1

:

max

row

print

<-

+

rnorm

20

=

0.1

<-

+

rnorm

20

=

0.1

<-

filter

>

min

&

<

max

>

min

&

<

max

<-

unique

$

# Albers projection

<-

mapproject

$

$

"rectangular"

=

38

$

<-

$

$

<-

$

# Map the projected points

pdf

sprintf

"%s-all.pdf"

plot

$

$

=

"n"

=

1

=

FALSE

=

""

=

""

for

<-

subset

==

lines

$

$

=

activity_color

$

=

0.4

dev.off