/
schemes-S3.R
327 lines (296 loc) · 10.9 KB
/
schemes-S3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#' Method for adding set and rep schemes
#' @param lhs \code{STMr_scheme} object
#' @param rhs \code{STMr_scheme} object
#' @return \code{STMr_scheme} object
#' @export
#' @examples
#' scheme1 <- scheme_wave()
#' warmup_scheme <- scheme_perc_1RM()
#' plot(warmup_scheme + scheme1)
`+.STMr_scheme` <- function(lhs, rhs) {
# +++++++++++++++++++++++++++++++++++++++++++
# Code chunk for dealing with R CMD check note
index <- NULL
scheme <- NULL
set <- NULL
max_set <- NULL
set_start <- NULL
# +++++++++++++++++++++++++++++++++++++++++++
df <- rbind(
data.frame(scheme = 1, lhs),
data.frame(scheme = 2, rhs)
)
scheme_index <- df %>%
dplyr::group_by(index, scheme) %>%
dplyr::summarize(max_set = max(set)) %>%
dplyr::group_by(index) %>%
dplyr::mutate(set_start = cumsum(max_set) - max_set) %>%
dplyr::select(-max_set) %>%
dplyr::ungroup()
scheme_df <- df %>%
dplyr::left_join(scheme_index, by = c("index", "scheme")) %>%
dplyr::mutate(set = set + set_start) %>%
dplyr::arrange(index, set)
# Call constructor
new_STMr_scheme(
index = scheme_df$index,
step = scheme_df$step,
set = scheme_df$set,
reps = scheme_df$reps,
adjustment = scheme_df$adjustment,
perc_1RM = scheme_df$perc_1RM
)
}
#' Plotting of the Set and Reps Scheme
#'
#' Functions for creating \code{ggplot2} plot of the Set and Reps Scheme
#'
#' @param x \code{STMr_scheme} object. See examples
#' @param type Type of plot. Options are "bar" (default), "vertical", and "fraction"
#' @param font_size Numeric. Default is 14
#' @param perc_str Percent string. Default is "%". Use "" to have more space on graph
#' @param ... Forwarded to \code{\link[ggfittext]{geom_bar_text}} and
#' \code{\link[ggfittext]{geom_fit_text}} functions. Can be used to se the highest
#' labels size, for example, using \code{size=5}. See documentation for these two
#' packages for more info
#' @return \code{ggplot2} object
#' @export
#' @examples
#' scheme <- scheme_wave(
#' reps = c(10, 8, 6, 10, 8, 6),
#' # Adjusting sets to use lower %1RM (RIR Inc method used, so RIR adjusted)
#' adjustment = c(4, 2, 0, 6, 4, 2),
#' vertical_planning = vertical_linear,
#' vertical_planning_control = list(reps_change = c(0, -2, -4)),
#' progression_table = progression_RIR_increment,
#' progression_table_control = list(volume = "extensive")
#' )
#'
#' plot(scheme)
#' plot(scheme, type = "vertical")
#' plot(scheme, type = "fraction")
plot.STMr_scheme <- function(x, type = "bar", font_size = 14, perc_str = "%", ...) {
switch(type,
"bar" = plot_scheme_bar(scheme = x, font_size = font_size, perc_str = perc_str, ...),
"vertical" = plot_scheme_vertical(scheme = x, font_size = font_size, perc_str = perc_str, ...),
"fraction" = plot_scheme_fraction(scheme = x, font_size = font_size, perc_str = perc_str, ...),
stop("Unknown plot `type`. Please use `bar`, `vertical`, `fraction`", call. = FALSE)
)
}
plot_scheme_bar <- function(scheme,
font_size,
perc_str,
...) {
# +++++++++++++++++++++++++++++++++++++++++++
# Code chunk for dealing with R CMD check note
index <- NULL
reps <- NULL
set <- NULL
perc_1RM <- NULL
reps_norm <- NULL
perc_1RM_norm <- NULL
perc_1RM_str <- NULL
set_index <- NULL
step_index <- NULL
# +++++++++++++++++++++++++++++++++++++++++++
# Prepare the scheme df
set_index_levels <- sort(unique(scheme$set))
step_index_levels <- paste0("Step #", sort(unique(scheme$index)))
scheme %>%
dplyr::mutate(set_index = factor(set, levels = set_index_levels)) %>%
dplyr::mutate(perc_1RM = round(perc_1RM * 100, 0)) %>%
dplyr::mutate(
step_index = factor(paste0("Step #", index), levels = step_index_levels),
reps_norm = 0.2 + range01(reps),
perc_1RM_norm = 1.35 + range01(perc_1RM),
perc_1RM_str = paste0(perc_1RM, perc_str)
) %>%
# Plot
ggplot2::ggplot() +
ggplot2::theme_grey(font_size) +
# %1RM
ggplot2::geom_col(
ggplot2::aes(x = step_index, y = perc_1RM_norm, group = set_index),
fill = color_orange,
width = 0.8, position = ggplot2::position_dodge(0.9), alpha = 0.7
) +
ggfittext::geom_bar_text(
ggplot2::aes(x = step_index, y = perc_1RM_norm, group = set_index, label = perc_1RM_str),
position = "dodge", place = "top", color = color_black, min.size = 0, ...
) +
# Reps
ggplot2::geom_col(
ggplot2::aes(x = step_index, y = reps_norm, group = set_index),
fill = color_blue,
width = 0.8, position = ggplot2::position_dodge(0.9), alpha = 0.8
) +
ggfittext::geom_bar_text(
ggplot2::aes(x = step_index, y = reps_norm, group = set_index, label = reps),
position = "dodge", place = "top", color = color_black, min.size = 0, ...
) +
ggplot2::ylab(NULL) +
ggplot2::xlab(NULL) +
ggplot2::theme(
legend.position = "none",
strip.background = ggplot2::element_rect(fill = "black"),
strip.text = ggplot2::element_text(color = "white"),
axis.ticks.y = ggplot2::element_blank(),
axis.text.y = ggplot2::element_blank(),
axis.ticks.x = ggplot2::element_blank(),
panel.background = ggplot2::element_rect(fill = "white"),
panel.grid.major = ggplot2::element_blank(),
panel.grid.minor = ggplot2::element_blank()
)
}
plot_scheme_vertical <- function(scheme,
font_size,
perc_str,
...) {
# +++++++++++++++++++++++++++++++++++++++++++
# Code chunk for dealing with R CMD check note
index <- NULL
reps <- NULL
set <- NULL
perc_1RM <- NULL
reps_norm <- NULL
perc_1RM_norm <- NULL
perc_1RM_str <- NULL
set_index <- NULL
step_index <- NULL
presc_center <- NULL
presc_left <- NULL
presc_right <- NULL
center <- NULL
# +++++++++++++++++++++++++++++++++++++++++++
set_index_levels <- sort(unique(scheme$set), decreasing = TRUE)
step_index_levels <- paste0("Step #", sort(unique(scheme$index)))
scheme %>%
dplyr::mutate(set_index = factor(set, levels = set_index_levels)) %>%
dplyr::mutate(perc_1RM = round(perc_1RM * 100, 0)) %>%
dplyr::mutate(
center = 0,
step_index = factor(paste0("Step #", index), levels = step_index_levels),
reps_norm = -(0.3 + range01(reps)),
perc_1RM_norm = (0.3 + range01(perc_1RM)),
presc_left = paste0(reps, " "),
presc_center = "x",
presc_right = paste0(" ", perc_1RM, perc_str)
) %>%
# plot
ggplot2::ggplot() +
ggplot2::theme_grey(font_size) +
# %1RM
ggplot2::geom_col(
ggplot2::aes(x = step_index, y = perc_1RM_norm, group = set_index),
fill = color_orange,
width = 0.8, position = ggplot2::position_dodge(0.9), alpha = 0.8
) +
# Reps
ggplot2::geom_col(
ggplot2::aes(x = step_index, y = reps_norm, group = set_index),
fill = color_blue,
width = 0.8, position = ggplot2::position_dodge(0.9), alpha = 0.8
) +
# Text
ggfittext::geom_fit_text(
ggplot2::aes(x = step_index, label = presc_center, y = center, group = set_index),
position = "dodge", min.size = 0, color = color_black, place = "center", ...
) +
ggfittext::geom_bar_text(
ggplot2::aes(x = step_index, label = presc_left, y = reps_norm, group = set_index),
position = "dodge", min.size = 0, color = color_black, place = "left", ...
) +
ggfittext::geom_bar_text(
ggplot2::aes(x = step_index, label = presc_right, y = perc_1RM_norm, group = set_index),
position = "dodge", min.size = 0, color = color_black, place = "left", ...
) +
ggplot2::coord_flip() +
ggplot2::scale_x_discrete(limits = rev) +
ggplot2::ylab(NULL) +
ggplot2::xlab(NULL) +
ggplot2::theme(
legend.position = "none",
strip.background = ggplot2::element_rect(fill = "black"),
strip.text = ggplot2::element_text(color = "white"),
axis.ticks.y = ggplot2::element_blank(),
axis.ticks.x = ggplot2::element_blank(),
axis.text.x = ggplot2::element_blank(),
panel.background = ggplot2::element_rect(fill = "white"),
panel.grid.major = ggplot2::element_blank(),
panel.grid.minor = ggplot2::element_blank()
)
}
plot_scheme_fraction <- function(scheme,
font_size,
perc_str,
...) {
# +++++++++++++++++++++++++++++++++++++++++++
# Code chunk for dealing with R CMD check note
index <- NULL
reps <- NULL
center <- NULL
presc_center <- NULL
set <- NULL
perc_1RM <- NULL
reps_norm <- NULL
perc_1RM_norm <- NULL
perc_1RM_str <- NULL
set_index <- NULL
step_index <- NULL
# +++++++++++++++++++++++++++++++++++++++++++
set_index_levels <- sort(unique(scheme$set))
step_index_levels <- paste0("Step #", sort(unique(scheme$index)))
scheme %>%
dplyr::mutate(set_index = factor(set, levels = set_index_levels)) %>%
dplyr::mutate(perc_1RM = round(perc_1RM * 100, 0)) %>%
dplyr::mutate(
center = 0,
step_index = factor(paste0("Step #", index), levels = step_index_levels),
reps_norm = -(0.3 + range01(reps)),
perc_1RM_norm = 0.3 + range01(perc_1RM),
perc_1RM_str = paste0(perc_1RM, perc_str),
presc_center = "|"
) %>%
# plot
ggplot2::ggplot() +
ggplot2::theme_grey(font_size) +
# %1RM
ggplot2::geom_col(
ggplot2::aes(x = step_index, y = perc_1RM_norm, group = set_index),
fill = color_orange,
width = 0.8, position = ggplot2::position_dodge(0.9), alpha = 0.7
) +
ggfittext::geom_bar_text(
ggplot2::aes(x = step_index, y = perc_1RM_norm, group = set_index, label = perc_1RM_str),
position = "dodge", min.size = 0, color = color_black, place = "bottom", ...
) +
# Reps
ggplot2::geom_col(
ggplot2::aes(x = step_index, y = reps_norm, group = set_index),
fill = color_blue,
width = 0.8, position = ggplot2::position_dodge(0.9), alpha = 0.8
) +
ggfittext::geom_bar_text(
ggplot2::aes(x = step_index, y = reps_norm, group = set_index, label = reps),
position = "dodge", min.size = 0, color = color_black, place = "bottom", ...
) +
# Fraction
ggfittext::geom_fit_text(
ggplot2::aes(x = step_index, y = center, group = set_index, label = presc_center),
position = "dodge", min.size = 0, color = color_black, angle = 90, ...
) +
ggplot2::ylab(NULL) +
ggplot2::xlab(NULL) +
ggplot2::theme(
legend.position = "none",
strip.background = ggplot2::element_rect(fill = "black"),
strip.text = ggplot2::element_text(color = "white"),
axis.ticks.y = ggplot2::element_blank(),
axis.text.y = ggplot2::element_blank(),
axis.ticks.x = ggplot2::element_blank(),
# axis.text.x = element_blank(),
panel.background = ggplot2::element_rect(fill = "white"),
panel.grid.major = ggplot2::element_blank(),
panel.grid.minor = ggplot2::element_blank()
)
}