Skip to content

Instantly share code, notes, and snippets.

@baogorek
Last active April 7, 2019 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baogorek/de6899c3aed43abb1eee82f5dfe3f800 to your computer and use it in GitHub Desktop.
Save baogorek/de6899c3aed43abb1eee82f5dfe3f800 to your computer and use it in GitHub Desktop.
library(ggplot2)
# Files are at ...
folder_path <- "c:/devl/swimming" # Update accordingly
perf_params <- get_perf_params(world_record_perf = 1.8,
able_bodied_perf = 0.5, limit = 2.0,
type = "jumping")
get_perf_in_cp <- function(perf, a, b, limit) {
b * log(a / (perf - limit))
}
get_swimming_data <- function(subject_id, folder_path, perf_params) {
file <- paste0(file.path(folder_path, "subject"), subject_id, ".txt")
swimming_df <- read.table(file)
swimming_df$subject <- subject_id
swimming_df$day <- 1:nrow(swimming_df)
names(swimming_df) <- c("training", "performance", "subject", "day")
swimming_df$performance <- ifelse(swimming_df$performance == 0, NA,
swimming_df$performance)
swimming_df$perf_cp <- get_perf_in_cp(swimming_df$perf, perf_params$a,
perf_params$b, perf_params$limit)
return(swimming_df)
}
subject1_df <- get_swimming_data(1, folder_path, perf_params)
subject2_df <- get_swimming_data(2, folder_path, perf_params)
subject3_df <- get_swimming_data(3, folder_path, perf_params)
subject4_df <- get_swimming_data(4, folder_path, perf_params)
subject5_df <- get_swimming_data(5, folder_path, perf_params)
subjects_df <- rbind(subject1_df, subject2_df, subject3_df, subject4_df,
subject5_df)
ggplot(subjects_df, aes(x = day, y = perf_cp)) +
geom_col(data = subjects_df, aes(y = 10 * training), color = "grey",
width = .2) +
geom_point() +
facet_grid(subject ~ .) +
annotate("text", label = "Relative training intensities (x10)",
x = 70, y = 25, color = "grey32") +
ggtitle("Performance and training for five swimmers") +
xlab("Day (n)") + ylab("Performance Scale") +
theme(text = element_text(size = 16))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment