Last active
December 19, 2024 23:52
-
-
Save selfawaresoup/9f3671514df95ec54527062ad3e341e3 to your computer and use it in GitHub Desktop.
5K Run Intervals Visualization in R with ggplot2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(dplyr) | |
library(tidyr) | |
library(viridis) | |
interval_plot <- function() { | |
tibble( | |
interval = c("Warm-up", "Work", "Recovery", "Work", "Recovery", "Work", "Recovery", "Work", "Recovery", "Work", "Recovery", "Finish"), | |
"2024-10-21" = c(500, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 500), | |
"2024-12-06" = c(500, 650, 150, 650, 150, 650, 150, 650, 150, 650, 150, 500), | |
"2024-12-11" = c(500, 700, 100, 700, 100, 700, 100, 700, 100, 700, 100, 500) | |
) |> | |
pivot_longer(cols = starts_with("2024"), names_to = "Date", values_to = "Distance") |> | |
mutate( | |
interval = ordered(interval, levels = c("Warm-up", "Work", "Recovery", "Finish")) | |
) |> | |
ggplot(aes(x = Distance, y = Date, group = Date, fill = interval)) + | |
geom_bar(stat = "identity") + | |
scale_fill_viridis(discrete = T, option = "rocket", direction = -1) + | |
theme_linedraw() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment