I wrote the following R-Code using the following dataset:
Dataset: Dataset
I want to display p-values in the “pre_post_plot” using stat_compare_means. But p-values don’t appear in the plot, and instead I am getting 24 warnings listed after the code:
library(tidyverse)
library(ggthemes)
library(ggpubr)
data <- read_csv("test_long.csv")
data <- data %>%
mutate(Date = as.Date(Date),
Timepoint = ifelse(Date == min(Date), "Pre", "Post"))
data_wide <- data %>%
select(-Date) %>%
pivot_wider(names_from = Timepoint, values_from = Value)
data_wide <- data_wide %>%
mutate(Change = Post - Pre)
pre_post_plot <- data %>%
ggplot(aes(x = as_factor(Timepoint), y = Value, color = Group)) +
geom_point(position = position_jitter(width = 0.1, height = 0), alpha = 0.5) +
geom_line(aes(group = interaction(Names, Test)), alpha = 0.5) +
stat_compare_means(aes(label = paste0("p = ", after_stat(p.format))), method = "t.test", paired = TRUE) +
facet_grid(Test ~ Group, scales = "free") +
theme_par() +
labs(title = "Pre and Post Intervention Fitness Test Results",
x = "",
y = "") +
theme(legend.position = "bottom") +
theme(plot.title = element_text(hjust = 0.5)) +
grids(linetype = "dashed")
change_plot <- data_wide %>%
ggplot(aes(x = Group, y = Change, color = Group)) +
geom_violin(alpha = 0.5) +
geom_jitter(width = 0.1, alpha = 0.5) +
facet_wrap(~ Test, scales = "free_y") +
theme_par() +
labs(title = "Change in Performance Pre to Post Intervention",
x = "",
y = "") +
theme(legend.position = "bottom") +
theme(plot.title = element_text(hjust = 0.5)) +
grids(linetype = "dashed")
pre_post_plot
change_plot
There were 24 warnings (use warnings() to see them)
warnings()
Warning messages:
1: Unknown or uninitialised column:p
.
2: Computation failed instat_compare_means()
.
Caused by error:
! argument “x” is missing, with no default
3: Unknown or uninitialised column:p
.
4: Computation failed instat_compare_means()
.
Caused by error:
! argument “x” is missing, with no default
5: Unknown or uninitialised column:p
.
6: Computation failed instat_compare_means()
.
Caused by error:
! argument “x” is missing, with no default
7: Unknown or uninitialised column:p
.
8: Computation failed instat_compare_means()
.
Caused by error:
! argument “x” is missing, with no default
9: Unknown or uninitialised column:p
.
10: Computation failed instat_compare_means()
.
Caused by error:
! argument “x” is missing, with no default
11: Unknown or uninitialised column:p
.
12: Computation failed instat_compare_means()
.
Caused by error:
! argument “x” is missing, with no default
13: Unknown or uninitialised column:p
.
14: Computation failed instat_compare_means()
.
Caused by error:
! argument “x” is missing, with no default
15: Unknown or uninitialised column:p
.
16: Computation failed instat_compare_means()
.
Caused by error:
! argument “x” is missing, with no default
17: Unknown or uninitialised column:p
.
18: Computation failed instat_compare_means()
.
Caused by error:
! argument “x” is missing, with no default
19: Unknown or uninitialised column:p
.
20: Computation failed instat_compare_means()
.
Caused by error:
! argument “x” is missing, with no default
21: Unknown or uninitialised column:p
.
22: Computation failed instat_compare_means()
.
Caused by error:
! argument “x” is missing, with no default
23: Unknown or uninitialised column:p
.
24: Computation failed instat_compare_means()
.
Caused by error:
! argument “x” is missing, with no default
Current Output without p-values
I am expecting the p-values to appear in the scientific notation in the “pre_post_plot”
Palash Gupta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.