Skip to contents

Visualizes the trend of aerobic decoupling over time.

Usage

plot_decoupling(
  stoken,
  activity_type = c("Run", "Ride"),
  decouple_metric = c("Pace_HR", "Power_HR"),
  start_date = NULL,
  end_date = NULL,
  min_duration_mins = 45,
  max_activities = 50,
  add_trend_line = TRUE,
  smoothing_method = "loess",
  decoupling_df = NULL
)

Arguments

stoken

A valid Strava token from `rStrava::strava_oauth()`. Required unless `decoupling_df` is provided.

activity_type

Type(s) of activities to analyze (e.g., "Run", "Ride").

decouple_metric

Metric basis: "Pace_HR" or "Power_HR".

start_date

Optional. Analysis start date (YYYY-MM-DD string or Date). Defaults to ~1 year ago.

end_date

Optional. Analysis end date (YYYY-MM-DD string or Date). Defaults to today.

min_duration_mins

Minimum activity duration (minutes) to include. Default 45.

max_activities

Max number of recent activities to fetch/analyze. Default 50.

add_trend_line

Add a smoothed trend line (`geom_smooth`)? Default `TRUE`.

smoothing_method

Smoothing method for trend line (e.g., "loess", "lm"). Default "loess".

decoupling_df

Optional. A pre-calculated data frame from `calculate_decoupling`. If provided, `stoken` and other calculation parameters are ignored.

Value

A ggplot object showing the decoupling trend.

Details

Plots the aerobic decoupling trend over time. Uses pre-calculated data or calls `calculate_decoupling` (can be slow).

Plots decoupling percentage ((EF_1st_half - EF_2nd_half) / EF_1st_half * 100). Positive values mean HR drifted relative to output. A 5 used as reference. If `decoupling_df` is not provided, calls `calculate_decoupling` first (can be slow and hit API limits).

Examples

# 使用模拟数据示例
data(Athlytics_sample_data)
if (!is.null(athlytics_sample_decoupling)) {
  p <- plot_decoupling(decoupling_df = athlytics_sample_decoupling)
  print(p)
}
#> Generating plot...
#> `geom_smooth()` using formula = 'y ~ x'


# \donttest{
# 使用真实数据的示例(需要认证)
stoken <- rStrava::strava_oauth(..., cache = TRUE)
#> Error: '...' used in an incorrect context

# 绘制最近30次跑步的Pace/HR解耦趋势
plot_decoupling(stoken = stoken,
                activity_type = "Run",
                decouple_metric = "Pace_HR",
                max_activities = 30)
#> Error: object 'stoken' not found

# 绘制最近骑行的Power/HR解耦趋势
plot_decoupling(stoken = stoken,
                activity_type = "Ride",
                decouple_metric = "Power_HR")
#> Error: object 'stoken' not found
# }