Home > Net >  How to plot treatment means per day with error bars and p values?
How to plot treatment means per day with error bars and p values?

Time:10-08

So I have data that were collected on Day 0, Day 15, and at the end of experiment (WEAN). These are weights of the animals between two treatments. It goes something like this:

PIG TRT DAY0 DAY15 WEAN 
1 SOY 1.48  5.22  8.35    
2 SOY 1.44  5.07  7.76   
3 SOY 1.66  5.30  9.46    
4 LIN 1.94  5.91 10.10   
5 LIN 1.54  4.96  9.01 
6 LIN 1.68  5.56  9.52 

It composes of 61 pigs in total. With ggplot2 or ggpubr, how can I perform the statistics and plot the treatment means with x = day of weight collection and y = weights in a single line plot, with error bars and p-value?

Thank you for any help!

CodePudding user response:

For your sample data, I think that your purpose is to plot mean of each pigs per treatment and date. You may try

library(tidyverse)

dummy %>%
  select(-PIG) %>%
  melt() %>%
  group_by(TRT, variable) %>%
  summarise(mean = mean(value),
            sd = sd(value),
            upper = mean   1.96 * sd,
            lower = mean - 1.96 * sd) %>%
  ungroup %>%
  ggplot(aes(variable, mean, color = TRT, group = TRT))  
  geom_line()   geom_point()   geom_errorbar(aes(ymin = lower, ymax = upper, width = 0.2), position = )  
  xlab("date")   ylab("mean of pig's weights")

enter image description here

  • Related