knitr::opts_chunk$set(
  echo = TRUE,
  comment = "#>",
  fig.path = "README-"
)
my.datadir <- "~/.bin/rweightlifting/inst/extdata/"
my.imagedir <- "~/.bin/rweightlifting/images/"
library(tidyverse)
library(data.table)
library(zoo)
library(rweightlifting)

Introduction

The rweightlifting package is designed to assist weightlifters and their coaches with creating programs and monitoring trainees' progress. The package contains functions for calculating common variables used in barbell training, such as 1-rep max, N-rep max, training maxes, tonnage, etc. The package includes an interactive shiny dashboard that allows weightlifters to visualize progress and compare common training programs against past results.

Reading Data

This package is designed for interactive use via the dashboard in the shiny directory. You'll need to point the data source for both weightlifting logs and body weight logs to the right directories to use the shiny app.

The load_csv_data function reads weightlifting logs. The expected format is one CSV file for each weightlifting program. The load_csv_data reads all CSV files in the specified directory. The function expects an input format that includes a header row, as follows:

date, exercise, equipment, variant, set1weight, set1reps, set2weight, set2reps, ..., setNweight, setNreps

weightlifting.log <- load_csv_data(datadir = my.datadir)
ifelse(
  dir.exists("/data/fitness/"),
  weight.dir <- "/data/fitness/",
  weight.dir <- "~/.fitness/Data/"
)

# Expects a CSV with date,weight as the header row
body.weight <- read.csv(paste(weight.dir, "body_weight.csv", sep=""), stringsAsFactors = FALSE)
body.weight$date <- as.Date(body.weight$date, "%Y-%m-%d")

# We're going to calculate a rolling mean for weight
# This allows us to calculates strength for dates where there's no weight measurement
all.dates <- data.frame(date = seq.Date(from = min(body.weight$date), to = Sys.Date(), by = 1))

body.weight <- body.weight %>%
  full_join(all.dates, by = "date") %>%
  arrange(date)

names(body.weight) <- c("date", "actual") 
body.weight$rolling.weight <- rollapply(body.weight$actual, 7, mean, by = 1, fill = NA, na.rm = TRUE, align = "right", partial = T)

body.weight <- body.weight %>%
  mutate(rolling.weight = ifelse(is.na(rolling.weight), NA, round(rolling.weight, 2)))

The function creates a data table with one set per row, as follows:

knitr::kable(tail(weightlifting.log, keepnums = FALSE))

Visualizing Data

The dashboard provided in the shiny directory contains many available visualizations for common metrics used in weightlifting. A few examples are provided below.

Diary View

This view shows each set performed; it is a way to show progress (and consistency) at a glance, as follows:

weightlifting.log %>%
  filter(exercise %in% c("squat", "deadlift")) %>%
  ggplot(aes(date, weight, color=interaction(equipment, variant), size=reps)) +
  facet_wrap( ~ exercise, ncol = 1, scales = "free_y") +
  geom_point(
    aes(
      date, 
      weight, 
      color = interaction(equipment, variant, lex.order = TRUE, sep = ","), 
      shape = reps > 0
    ), 
    alpha=0.33
  ) +
  scale_shape_manual(values = c(4, 16)) +
  scale_radius(range = c(1.5, 8), breaks=c(3,6,9,12,15)) +
  scale_y_continuous(
    position="right",
    minor_breaks=function(x){
      seq(0, ceiling(max(x)), 25)
      }) +
  scale_x_date(
    date_breaks = "6 month", date_labels = "%b %Y",
    date_minor_breaks = "2 month"
  ) +
  labs(x = "", y = "") +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),
    legend.position = "none"
  ) +
  geom_vline(aes(xintercept = as.numeric(Sys.Date())), color=alpha("green", 0.5), linetype="dashed")

In this view, you can see that a linear progression program was followed at the beginning, followed by more complex programming over time. You can also see a gaps around January 2018 (when I tore my calf playing tennis) and April 2020 (when gyms were closed due to the COVID-19 pandemic). The colors indicate different exercise, equipment, and exercise variants. Missed attempts (i.e., reps = 0) are denoted with an X shape.

Strength View

The strength view uses a caculated one-rep max to show progress in strength over time. It is a way to compare absolute strength across different set/rep schemes.

top_sets(weightlifting.log, use.method = "wathan") %>%
  filter(exercise %in% c("squat", "bench", "press", "deadlift")) %>%
  filter(equipment %in% c("barbell")) %>%
  filter(variant %in% c("high bar", "low bar", "flat", "overhead", "conventional")) %>%
  ggplot(aes(date, est.max)) +
    geom_point(aes(fill = program, color = program), alpha = 0.5, stroke = 0, size = 2, na.rm = TRUE) +
    geom_smooth(formula = y ~ x, method = "loess", se = TRUE, span = 0.25, na.rm = TRUE) +
    facet_wrap(~ exercise, scales = "free_y") +
    labs(y = "", x = "") +
    scale_y_continuous(
      position="right",
      minor_breaks=function(x){
        seq(0, ceiling(max(x)), 25)
      }) +
    scale_x_date(
      date_breaks = "6 month", date_labels = "%b %Y",
      date_minor_breaks = "2 month"
    ) +
    theme(
      axis.text.x = element_text(angle = 45, hjust = 1),
      legend.position = "none"
    )

Broadly speaking, this view shows a lifter with increasing absolute strength over time. Bubbles of different colors denote different programs.

A similar view in the shiny app shows relative strength, which is obtained by dividing a calculated 1-RM by the lifter's body weight. This view is useful for comparing a lifter's performance to strength standards, which commonly reference multiples of body weight (e.g., 1x, 2x, 2.5x). It is also useful for monitoring performance across bulking or cutting cycles.

top_sets(weightlifting.log, use.method = "wathan") %>%
  rename(., lift.weight = weight) %>%
  filter(exercise %in% c("squat", "bench", "press", "deadlift")) %>%
  filter(equipment %in% c("barbell")) %>%
  filter(variant %in% c("high bar", "low bar", "flat", "overhead", "conventional")) %>%
  left_join(., body.weight, by = c("date" = "date")) %>%
  mutate(strength.to.weight.ratio = round(est.max / rolling.weight, 3)) %>%
  mutate(intensity = round(lift.weight / est.max, 3)) %>%
  ggplot(aes(date, strength.to.weight.ratio)) +
    geom_point(aes(fill = program, color = program,), 
    alpha = 0.5, na.rm = TRUE) +
    geom_smooth(formula = y ~ x, method = "loess", se = TRUE, span = 0.25, na.rm = TRUE) +
    facet_wrap(~ exercise, scales = "free_y") +
    labs(y = "", x = "") +
    scale_y_continuous(
      position="right",
      minor_breaks=function(x){
        seq(0, ceiling(max(x)), 25)
      }) +
    scale_x_date(
      date_breaks = "6 month", date_labels = "%b %Y",
      date_minor_breaks = "2 month"
    ) +
    theme(
      axis.text.x = element_text(angle = 45, hjust = 1),
      legend.position = "none"
    )

Note that the curves for absolute and relative strength are similar but not identical. As one example, the estimated 1RM for the deadlift has hovered around 500 - 525 since December 2018. However, the absolute strength has declined from a high of around 2.5x in June 2019 to around 2.3-2.4x as of the time of writing (this is attributable primarily to the, ahem, COVID nineteen pounds). I generally use the absolute strength view during bulking cycles (for comparison against all-time strength) and the relative strength view during cutting cycles (to make sure I'm not losing ground).

Other Views

There are many other views shown in the dashboard located in the shiny directory. These include:

Creating a New Program

Weightlifters change programming periodically in order to accommodate different goals, such as to increase the amount of work performed, to change set/rep ranges, or to start fresh after a layoff due to illness. The rweightlifting package contains functions designed to assist the coach or lifter in preparing a new program. The starting position for the new program is tied to a specific percentage of the lifter's previous one-rep maximum, which is called the training max. For instance, a typical starting point after a week's vacation might set the training max at 90% of the lifter's calculated 1RM over the last month. The functions contain sensible defaults; the dashboard permits a user to adjust pertinent variables in order to get the desired level of difficulty.

For the lifter identified above, the package provides the following of a new program based on Jim Wendler's basic 3-week 5-3-1 program (this is the first week only):

knitr::kable(
  head(
    rweightlifting::program_schedule("wendler_531", weightlifting.log) %>%
      left_join(
        weightlifting.log %>%
          group_by(exercise, equipment, variant, weight) %>%
          summarize(max.reps = max(reps), .groups = "drop")
      , by = c("exercise", "equipment", "variant", "weight"))
  , 12)
)

For convenience, we can also add the maximum number of reps at each specific weight the trainee is supposed to lift. This assists with giving the lifter a "rep PR" to shoot for each time in the gym, which is helpful for programs that recommend an AMRAP (as many reps as possible) scheme for work sets such as Wender 5-3-1.

This information can be displayed alongside historical training information to provide a visual representation of a new program's potential for gains over time:

deload_cycles <- 3

rweightlifting::program_schedule("wendler_531", weightlifting.log, cycles = 12, deload_every = deload_cycles) %>%
  mutate(
    date = Sys.Date() + (cycle - 1) * wendler_531()$duration + (wendler_531()$deload_duration * ((cycle - 1) %/% as.numeric(deload_cycles))) + (day - 1)
  ) %>%
  bind_rows(weightlifting.log) %>%
  filter(exercise %in% c("squat", "deadlift")) %>%
  ggplot(aes(date, weight, color=interaction(equipment, variant), size=reps)) +
  facet_wrap( ~ exercise, ncol = 1) +
  geom_point(
    aes(
      date, 
      weight, 
      color = interaction(equipment, variant, lex.order = TRUE, sep = ","), 
      shape = reps > 0
    ), 
    alpha=0.33
  ) +
  scale_shape_manual(values = c(4, 16)) +
  scale_radius(range = c(1.5, 8), breaks=c(3,6,9,12,15)) +
  scale_y_continuous(
    position="right",
    breaks = function(x) {
      seq(0, ceiling(max(x)), 100)
    },
    minor_breaks=function(x){
      seq(0, ceiling(max(x)), 25)
    }
  ) +
  scale_x_date(
    date_breaks = "6 month", date_labels = "%b %Y",
    date_minor_breaks = "2 month"
  ) +
  labs(x = "", y = "") +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),
    legend.position = "none"
  ) +
  geom_vline(aes(xintercept = as.numeric(Sys.Date())), color=alpha("green", 0.5), linetype="dashed")

The vertical green line represents today (currently r format(Sys.Date(), "%d %b %Y")); projected performance resulting from compliance with the new program is plotted to the right of the green line. Another feature displayed here is the ability to program deload weeks every so often -- in this case after every 3 cycles. Note that the projected work doesn't necessarily include accessory or supplemental work that may appear in historical data.

The supported programs include:

program_descriptions <- c()

for (i in available_programs()) {
  program_descriptions <- c(program_descriptions, eval(call(i))$name)
}

program_descriptions

It is desired that future versions of the package's dashboard will permit creation of custom programs on an exercise-by-exercise basis.



titaniumtroop/rweightlifting documentation built on April 24, 2022, 5:30 a.m.