Adding significance values between groups on line plot in R (ggplot)

81 Views Asked by At

I've created a line plot that displays weight data over time in a diet study. I am trying to add significance values between each group at the end of the time period. My data is similar to the ToothGrowth dataset with multiple groups (instead of just two in the Supp column). I've checked that each sample group at the end of the time period is normally distributed so possibly I'd run a t-test between these groups. This is what I'd want the graph to look like -> Weights over time line plot

enter image description here

Any help would be appreciated!

-shasabhi1

So far I've used ggplot and ggline (ggpubr package) and have successfully made line plots and standard error of means within each group and time. I've tried the following code:

weightsFile_stats <- summarySE(weightsFile, measurevar = "Weight", groupvars = c("Diet_Sex","Weeks"))
my_comparisons <-(c("Chow Male", "HFD Male"))
ggplot(weightsFile_stats, aes(x=Weeks, y=Weight, group=Diet_Sex, colour=Diet_Sex)) + 
geom_errorbar(aes(ymin=Weight-se, ymax=Weight+se), width=.1) +
ylab("Weight (g)") +
xlab("Weeks") +
guides(color = guide_legend(title = "Groups")) +
geom_line() +
geom_point() +
scale_color_manual(values =c("#669bbc", "#c1121f", "#003049", "#780000")) + 
stat_compare_means(aes(group = Diet_Sex), label = "p.signif", comparisons = my_comparisons)

But I get the following error code:

Warning message: Computation failed in stat_signif() Caused by error in if (scales$x$map(comp[1]) == data$group[1] | manual) ...: missing value where TRUE/FALSE needed
0

There are 0 best solutions below