Learn R Programming

rStrava (version 1.0.0)

get_heat_map: Makes a heat map from your activity data

Description

Makes a heat map from your activity data

Usage

get_heat_map(act_data, ...)

# S3 method for list get_heat_map(act_data, acts = 1, alpha = NULL, f = 0.1, key = NULL, add_elev = FALSE, as_grad = FALSE, distlab = TRUE, distval = 0, size = 0.5, col = "red", expand = 10, maptype = "terrain", source = "google", units = "metric", ...)

# S3 method for actframe get_heat_map(act_data, alpha = NULL, f = 1, key = NULL, add_elev = FALSE, as_grad = FALSE, distlab = TRUE, distval = 0, size = 0.5, col = "red", expand = 10, maptype = "terrain", source = "google", ...)

# S3 method for strframe get_heat_map(act_data, alpha = NULL, f = 1, filltype = c("elevation", "distance", "slope", "speed"), distlab = TRUE, distval = 0, size = 0.5, col = "red", expand = 10, maptype = "terrain", source = "google", ...)

Arguments

act_data

an activities list object returned by get_activity_list, an actframe returned by compile_activities, or a strfame returned by get_activity_streams

...

arguments passed to or from other methods

acts

numeric indicating which activities to plot based on index in the activities list, defaults to most recent

alpha

the opacity of the line desired. A single activity should be 1. Defaults to 0.5

f

number specifying the fraction by which the range should be extended for the bounding box of the activities, passed to make_bbox

key

chr string of Google API key for elevation data, passed to elevation, see details

add_elev

logical indicating if elevation is overlayed by color shading on the activity lines

as_grad

logical indicating if elevation is plotted as percent gradient, applies only if add_elev = TRUE

distlab

logical if distance labels are plotted along the route with geom_label_repel

distval

numeric indicating rounding factor for distance labels which has direct control on label density, see details

size

numeric indicating width of activity lines

col

chr string indicating either a single color of the activity lines if add_grad = FALSE or a color palette passed to scale_fill_distiller if add_grad = TRUE

expand

a numeric multiplier for expanding the number of lat/lon points on straight lines. This can create a smoother elevation gradient if add_grad = TRUE. Set expand = 1 to suppress this behavior.

maptype

chr string indicating the base map type relevant for the source, passed to get_map

source

chr string indicating map source, passed to get_map, currently only "google" and "osm" are supported

units

chr string indicating plot units as either metric or imperial, this has no effect if input data are already compiled with compile_activities

filltype

chr string specifying which stream variable to use for filling line segments, applies only to strframe objects, acceptable values are "elevation", "distance", "slope", or "speed"

Value

plot of activity on a Google map

Details

uses get_latlon to produce a dataframe of latitudes and longitudes to use in the map. Uses ggmap to produce the map and ggplot2 to plot the route.

The Google API key for elevation is easy to obtain, follow instructions here: https://developers.google.com/maps/documentation/elevation/#api_key

A Google API key is needed if using any map services where source = "google". The same key used for the elevation API can be used but must be registered externally with the ggmap package using register_google() before executing get_heat_map(). See the examples.

The distval argument is passed to the digits argument of round. This controls the density of the distance labels, e.g., 1 will plot all distances in sequenc of 0.1, 0 will plot all distances in sequence of one, -1 will plot all distances in sequence of 10, etc.

Examples

Run this code
# NOT RUN {
# get my activities
stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE))
my_acts <- get_activity_list(stoken)

# register Google maps API key
library(ggmap)
register_google('xxxxxxxxxxx') # enter your key here

# default
get_heat_map(my_acts, acts = 1, alpha = 1)

# plot elevation on locations, requires key
mykey <- 'Get Google API key'
get_heat_map(my_acts, acts = 1, alpha = 1, key = mykey, add_elev = TRUE, col = 'Spectral', size = 2)

# compile first, change units
my_acts <- compile_activities(my_acts, acts = 156, units = 'imperial')
get_heat_map(my_acts, key = mykey, alpha = 1, add_elev = T, col = 'Spectral', size = 2, 
  maptype = 'satellite')
# }

Run the code above in your browser using DataLab