get_heat_map: Makes a heat map from your activity data

View source: R/get_heat_map.R

get_heat_mapR Documentation

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 class 'list'
get_heat_map(
  act_data,
  key,
  acts = 1,
  id = NULL,
  alpha = NULL,
  add_elev = FALSE,
  as_grad = FALSE,
  distlab = TRUE,
  distval = 0,
  size = 0.5,
  col = "red",
  expand = 10,
  maptype = "CartoDB.Positron",
  zoom = 14,
  units = "metric",
  ...
)

## S3 method for class 'actframe'
get_heat_map(
  act_data,
  key,
  alpha = NULL,
  add_elev = FALSE,
  as_grad = FALSE,
  distlab = TRUE,
  distval = 0,
  size = 0.5,
  col = "red",
  expand = 10,
  maptype = "CartoDB.Positron",
  zoom = 14,
  ...
)

## S3 method for class 'strframe'
get_heat_map(
  act_data,
  alpha = NULL,
  filltype = "elevation",
  distlab = TRUE,
  distval = 0,
  size = 0.5,
  col = "red",
  expand = 10,
  maptype = "CartoDB.Positron",
  zoom = 14,
  ...
)

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

key

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

acts

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

id

optional character vector to specify the id(s) of the activity/activities to plot, acts is ignored if provided

alpha

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

add_elev

logical indicating if elevation is shown 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

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 provider for the basemap, see details

zoom

numeric indicating zoom factor for map tiles, higher numbers increase resolution

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"

Details

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

A Google API key is needed for the elevation data and must be included with function execution. The API key can be obtained following the instructions here: https://developers.google.com/maps/documentation/elevation/#api_key

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 sequence of 0.1, 0 will plot all distances in sequence of one, -1 will plot all distances in sequence of 10, etc.

The base map type is selected with the maptype argument. The zoom value specifies the resolution of the map. Use higher values to download map tiles with greater resolution, although this increases the download time. Acceptable options for maptype include "OpenStreetMap", "OpenStreetMap.DE", "OpenStreetMap.France", "OpenStreetMap.HOT", "OpenTopoMap", "Esri.WorldStreetMap", "Esri.DeLorme", "Esri.WorldTopoMap", "Esri.WorldImagery", "Esri.WorldTerrain", "Esri.WorldShadedRelief", "Esri.OceanBasemap", "Esri.NatGeoWorldMap", "Esri.WorldGrayCanvas", "CartoDB.Positron", "CartoDB.PositronNoLabels", "CartoDB.PositronOnlyLabels", "CartoDB.DarkMatter", "CartoDB.DarkMatterNoLabels", "CartoDB.DarkMatterOnlyLabels", "CartoDB.Voyager", "CartoDB.VoyagerNoLabels", or "CartoDB.VoyagerOnlyLabels".

Value

A ggplot object showing a map with activity locations.

Author(s)

Daniel Padfield, Marcus Beck

Examples

## 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)

# default, requires Google key
mykey <- 'Get Google API key'
get_heat_map(my_acts, acts = 1, alpha = 1, key = mykey)

# plot elevation on locations, requires 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)

## End(Not run)

rStrava documentation built on Oct. 23, 2024, 5:06 p.m.