diff --git a/R/get_heat_map.R b/R/get_heat_map.R index 44d1230..1d0566c 100644 --- a/R/get_heat_map.R +++ b/R/get_heat_map.R @@ -11,7 +11,7 @@ #' @param acts numeric indicating which activities to plot based on index in the activities list, defaults to most recent #' @param id optional numeric vector to specify the id(s) of the activity/activities to plot, \code{acts} is ignored if provided #' @param alpha the opacity of the line desired. A single activity should be 1. Defaults to 0.5 -#' @param add_elev logical indicating if elevation is overlayed by color shading on the activity lines +#' @param add_elev logical indicating if elevation is shown by color shading on the activity lines #' @param as_grad logical indicating if elevation is plotted as percent gradient, applies only if \code{add_elev = TRUE} #' @param filltype chr string specifying which stream variable to use for filling line segments, applies only to \code{strframe} objects, acceptable values are \code{"elevation"}, \code{"distance"}, \code{"slope"}, or \code{"speed"} #' @param distlab logical if distance labels are plotted along the route @@ -185,10 +185,7 @@ get_heat_map.actframe <- function(act_data, key, alpha = NULL, add_elev = FALSE, dplyr::ungroup(.) %>% dplyr::select(-tosel, -diffdist) %>% dplyr::mutate(distance = as.character(round(distance))) - # final <- temp[nrow(temp), ] - # final$distance <- format(final$distance, nsmall = 1, digits = 1) - # disttemp <- rbind(disttemp, final) - + # add to plot p <- p + ggspatial::geom_spatial_label_repel( @@ -252,7 +249,7 @@ get_heat_map.strframe <- function(act_data, alpha = NULL, filltype = 'elevation' alti <- stats::approx(x= x$altitude, n = expand * nrow(x))$y grds <- stats::approx(x= x$grade_smooth, n = expand * nrow(x))$y vels <- stats::approx(x= x$velocity_smooth, n = expand * nrow(x))$y - data.frame(id = unique(x$id), lat = yint, lng = xint, distance = dist, elevation = alti, slope = grds, speed = vels) + data.frame(id = unique(x$id), lat = yint, lon = xint, distance = dist, elevation = alti, slope = grds, speed = vels) }) temp <- do.call('rbind', temp) @@ -270,7 +267,7 @@ get_heat_map.strframe <- function(act_data, alpha = NULL, filltype = 'elevation' if(filltype == 'slope') leglab <- '%' else leglab <- unit_vals[filltype] p <- pbase + - ggspatial::geom_spatial_path(ggplot2::aes_string(x = 'lng', y = 'lat', group = 'id', colour = filltype), + ggspatial::geom_spatial_path(ggplot2::aes_string(x = 'lon', y = 'lat', group = 'id', colour = filltype), alpha = alpha, data = temp, linewidth = size, crs = 4326) + ggplot2::scale_colour_distiller(leglab, palette = col) @@ -288,21 +285,21 @@ get_heat_map.strframe <- function(act_data, alpha = NULL, filltype = 'elevation' dplyr::ungroup(.) %>% dplyr::select(-tosel, -diffdist) %>% dplyr::mutate(distance = as.character(round(distance))) - # final <- temp[nrow(temp), ] - # final$distance <- format(final$distance, nsmall = 1, digits = 1) - # disttemp <- rbind(disttemp, final) # add to plot p <- p + ggspatial::geom_spatial_label_repel( data = disttemp, - ggplot2::aes(x = lng, y = lat, label = distance), + ggplot2::aes(x = lon, y = lat, label = distance), point.padding = grid::unit(0.4, "lines"), crs = 4326 ) } + p <- p + + ggplot2::coord_sf(xlim = range(temp$lon), ylim = range(temp$lat)) + return(p) } \ No newline at end of file diff --git a/README.Rmd b/README.Rmd index c65a529..f2bc7a5 100644 --- a/README.Rmd +++ b/README.Rmd @@ -109,41 +109,42 @@ An example creating a heat map of activities: ```{r message = F, fig.height = 5.5, fig.width = 7, message = F, warning = F} library(dplyr) -# get activities, get activities by lat/lon, distance, plot -my_acts <- get_activity_list(stoken) -act_data <- compile_activities(my_acts) %>% - filter(start_latlng2 < -86.5 & start_latlng2 > -88.5) %>% - filter(start_latlng1 < 31.5 & start_latlng1 > 30) %>% - filter(distance > 20) - -get_heat_map(act_data, key = google_key, col = 'darkgreen', size = 2, distlab = F, f = 0.4) +# get activities by date range +my_acts <- get_activity_list(stoken, after = as.Date('2020-12-31')) +act_data <- compile_activities(my_acts) + +# subset by location +toplo <- act_data %>% + filter(grepl('Run$', name)) %>% + filter(start_latlng2 < -82.63 & start_latlng2 > -82.65) %>% + filter(start_latlng1 < 27.81 & start_latlng1 > 27.78) + +get_heat_map(toplo, key = google_key, col = 'darkred', size = 1.5, distlab = F, alpha = 0.6, zoom = 13) ``` Plotting elevation and grade for a single ride: ```{r} -# activity id -id <- 1784292574 +# get data for a single activity +my_acts <- get_activity_list(stoken, id = 1784292574) +act_data <- compile_activities(my_acts) # plot elevation along a single ride -get_heat_map(my_acts, id = id, alpha = 1, add_elev = T, distlab = F, key = google_key, size = 2, col = 'Spectral', units = 'imperial') +get_heat_map(my_acts, alpha = 1, add_elev = T, distlab = F, key = google_key, size = 2, col = 'Spectral', units = 'imperial') # plot % gradient along a single ride -get_heat_map(my_acts, id = id, alpha = 1, add_elev = T, distlab = F, as_grad = T, key = google_key, size = 2, col = 'Spectral', expand = 5, units = 'imperial') +get_heat_map(my_acts, alpha = 1, add_elev = T, distlab = F, as_grad = T, key = google_key, size = 2, col = 'Spectral', units = 'imperial') ``` Get elevation profiles for activities: ```{r message = F, fig.height = 3, fig.width = 9} -# get activities -my_acts <- get_activity_list(stoken) - -get_elev_prof(my_acts, id = id, key = google_key, units = 'imperial') -get_elev_prof(my_acts, id = id, key = google_key, units = 'imperial', total = T) +get_elev_prof(my_acts, key = google_key, units = 'imperial') +get_elev_prof(my_acts, key = google_key, units = 'imperial', total = T) ``` Plot average speed per split (km or mile) for an activity: ```{r message = F, fig.height = 3, fig.width = 9} # plots for most recent activity -plot_spdsplits(my_acts, stoken, id = id, units = 'imperial') +plot_spdsplits(my_acts, stoken, units = 'imperial') ``` Additional functions are provided to get "stream" information for individual activities. Streams provide more detailed information about location, time, speed, elevation, gradient, cadence, watts, temperature, and moving status (yes/no) for an individual activity. @@ -151,7 +152,7 @@ Additional functions are provided to get "stream" information for individual act Use `get_activity_streams` for detailed info about activities: ```{r, fig.height = 4, fig.with = 4} # get streams for the first activity in my_acts -strms_data <- get_activity_streams(my_acts, stoken, id = id) +strms_data <- get_activity_streams(my_acts, stoken) head(strms_data) ``` diff --git a/man/figures/unnamed-chunk-12-1.png b/man/figures/unnamed-chunk-12-1.png index 51a632f..ab2b462 100644 Binary files a/man/figures/unnamed-chunk-12-1.png and b/man/figures/unnamed-chunk-12-1.png differ diff --git a/man/figures/unnamed-chunk-13-1.png b/man/figures/unnamed-chunk-13-1.png index 2339ed7..b60db9b 100644 Binary files a/man/figures/unnamed-chunk-13-1.png and b/man/figures/unnamed-chunk-13-1.png differ diff --git a/man/figures/unnamed-chunk-13-2.png b/man/figures/unnamed-chunk-13-2.png index 889be8b..02fdfbc 100644 Binary files a/man/figures/unnamed-chunk-13-2.png and b/man/figures/unnamed-chunk-13-2.png differ diff --git a/man/get_heat_map.Rd b/man/get_heat_map.Rd index c688d10..c5e0a16 100644 --- a/man/get_heat_map.Rd +++ b/man/get_heat_map.Rd @@ -71,7 +71,7 @@ get_heat_map(act_data, ...) \item{alpha}{the opacity of the line desired. A single activity should be 1. Defaults to 0.5} -\item{add_elev}{logical indicating if elevation is overlayed by color shading on the activity lines} +\item{add_elev}{logical indicating if elevation is shown by color shading on the activity lines} \item{as_grad}{logical indicating if elevation is plotted as percent gradient, applies only if \code{add_elev = TRUE}}