I am trying to perform t-tests between two states called n and t. These populations are measured through times 1 to 4. Each time point then belongs to two further groups above them. So for example:
Group-->Sub-group-->Time points-->State-->Var_measured
Var_measured<-sample(248)
State<-rep(c("t","n"), 124)
Time<-as.factor(sample(1:4, 62,replace = TRUE))
Sub_group<-sample(c("Met","Tet","Pep","Cep"),62, replace = TRUE)
Group<-sample(c("AA","Gly"),62, replace = TRUE)
df<-data.frame(Var_measured,State,Time,Sub_group,Group)
So from this data frame I would need a list of p-values from a t-test between each Sub_group at each Time point for State n and t. This is best visualised with an example:
p<-ggplot(df, aes(x= Time, y= Var_measured, fill= State))+
geom_boxplot()+
# coord_cartesian(ylim = c(0, 150000))+
theme(axis.text.x=element_text(angle=90)) +
facet_grid(Group ~ Sub_group, scales = "free_y")
p
I would ultimately like be able to show significance markers on the boxplots (as shown by this 'impeccable' paint job below). Any help would be appreciated.
Best, M