library(ggplot2)
library(ggcorrplot)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.1 ✔ readr 2.2.0
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ lubridate 1.9.5 ✔ tibble 3.3.1
## ✔ purrr 1.2.2 ✔ tidyr 1.3.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(googlesheets4)
gs4_deauth()
fourm <- read_sheet("https://docs.google.com/spreadsheets/d/1lGsBllFG-lXHwFVuOo-lwkgOSpDHEjzGqv_8CkNKM78/edit?usp=sharing", sheet = "Sheet3")
## ✔ Reading from "Experment data".
## ✔ Range ''Sheet3''.
library(tidyverse)
library(ggpubr) # for easy significance annotations
# Add a row/subject ID before reshaping — important for paired analysis
fourm <- fourm %>% mutate(id = row_number())
fourm_long <- fourm %>%
pivot_longer(cols = c(A, C, N), names_to = "condition", values_to = "time")
ggplot(fourm_long, aes(x = condition, y = time, fill = condition)) +
geom_boxplot() +
geom_jitter(width = 0.1, alpha = 0.5) + # show individual points too
labs(title = "Time by Condition", x = "Condition", y = "Time") +
theme_minimal() +
theme(legend.position = "none") +
scale_fill_manual(values = c("#FF6B6B", "#4ECDC4", "#45B7D1"))
## Warning: Removed 1 row containing non-finite outside the scale range
## (`stat_boxplot()`).
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).

summary_stats <- fourm_long %>%
group_by(condition) %>%
summarise(
mean_time = mean(time, na.rm = TRUE),
se = sd(time, na.rm = TRUE) / sqrt(sum(!is.na(time)))
)
ggplot(summary_stats, aes(x = condition, y = mean_time, fill = condition)) +
geom_col(width = 0.6) +
geom_errorbar(aes(ymin = mean_time - se, ymax = mean_time + se), width = 0.2) +
labs(title = "Mean Time by Condition (± SE)", x = "Condition", y = "Mean Time") +
theme_minimal() +
theme(legend.position = "none")

ggplot(fourm_long, aes(x = time, fill = condition)) +
geom_density(alpha = 0.4) +
labs(title = "Distribution of Time by Condition", x = "Time", y = "Density") +
theme_minimal()
## Warning: Removed 1 row containing non-finite outside the scale range
## (`stat_density()`).

ggplot(fourm_long, aes(x = condition, y = time, group = id)) +
geom_line(alpha = 0.4, color = "gray50") +
geom_point(aes(color = condition), size = 2) +
labs(title = "Individual Time Trajectories Across Conditions", x = "Condition", y = "Time") +
theme_minimal()
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_line()`).
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).

diffs <- fourm %>%
mutate(
`A - C` = A - C,
`A - N` = A - N,
`C - N` = C - N
) %>%
select(id, `A - C`, `A - N`, `C - N`) %>%
pivot_longer(-id, names_to = "comparison", values_to = "diff")
ggplot(diffs, aes(x = comparison, y = diff, fill = comparison)) +
geom_boxplot() +
geom_jitter(width = 0.1, alpha = 0.5) +
geom_hline(yintercept = 0, linetype = "dashed", color = "red") +
labs(title = "Pairwise Time Differences", x = NULL, y = "Difference in Time") +
theme_minimal() +
theme(legend.position = "none")
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_boxplot()`).
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

ggplot(fourm_long, aes(x = condition, y = time, fill = condition)) +
geom_violin(alpha = 0.5) +
geom_boxplot(width = 0.15, fill = "white") +
labs(title = "Distribution of Time by Condition", x = "Condition", y = "Time") +
theme_minimal() +
theme(legend.position = "none")
## Warning: Removed 1 row containing non-finite outside the scale range
## (`stat_ydensity()`).
## Warning: Removed 1 row containing non-finite outside the scale range
## (`stat_boxplot()`).
