|
@ -1,4 +1,4 @@ |
|
|
ggstats_add_xy<-function(table_stat, table, xcol=NULL, group, y="max", bracket.offset=0.05, bracket.inspace=0.05, exclude_group=NULL){ |
|
|
|
|
|
|
|
|
ggstats_add_xy<-function(table_stat, table, xcol=NULL, group, y="max", bracket.offset=0.05, bracket.inspace=0.05, exclude_group=NULL, dodge=0.75){ |
|
|
## Adapted version to fit rstatix output |
|
|
## Adapted version to fit rstatix output |
|
|
value.var<-table_stat[[1,".y."]] |
|
|
value.var<-table_stat[[1,".y."]] |
|
|
if (is.null(xcol)){ |
|
|
if (is.null(xcol)){ |
|
@ -14,7 +14,7 @@ ggstats_add_xy<-function(table_stat, table, xcol=NULL, group, y="max", bracket.o |
|
|
} |
|
|
} |
|
|
if (y == "max"){ |
|
|
if (y == "max"){ |
|
|
agg<-table_agg %>% summarise(max=max(.data[[value.var]], na.rm = T)) |
|
|
agg<-table_agg %>% summarise(max=max(.data[[value.var]], na.rm = T)) |
|
|
if(!is.na(exclude_group)){agg<-table_agg %>% group_by(.data[[exclude_group]]) %>% summarise(max=max(.data[[value.var]], na.rm=T))} |
|
|
|
|
|
|
|
|
if(!is.null(exclude_group)){agg<-table_agg %>% group_by(.data[[exclude_group]]) %>% summarise(max=max(.data[[value.var]], na.rm=T))} |
|
|
}else if (y == "mean"){ |
|
|
}else if (y == "mean"){ |
|
|
agg<-table %>% group_by(.data[[x]],.data[[group]]) %>% summarise(mean=mean(.data[[value.var]], na.rm=T)) %>% spread(group, mean) |
|
|
agg<-table %>% group_by(.data[[x]],.data[[group]]) %>% summarise(mean=mean(.data[[value.var]], na.rm=T)) %>% spread(group, mean) |
|
|
agg<- data.frame(x=agg[,1], "max"=apply(agg[,2:ncol(agg)], 1, max, na.rm=T)) |
|
|
agg<- data.frame(x=agg[,1], "max"=apply(agg[,2:ncol(agg)], 1, max, na.rm=T)) |
|
@ -42,8 +42,8 @@ ggstats_add_xy<-function(table_stat, table, xcol=NULL, group, y="max", bracket.o |
|
|
t<-tibble("y.position"=merge(table_stat, agg ,sort=F)[,"max"]+diff(range(table[value.var], na.rm = T))*bracket.offset, |
|
|
t<-tibble("y.position"=merge(table_stat, agg ,sort=F)[,"max"]+diff(range(table[value.var], na.rm = T))*bracket.offset, |
|
|
"groups"=group.list, |
|
|
"groups"=group.list, |
|
|
"x.temp"=x.index, |
|
|
"x.temp"=x.index, |
|
|
"xmin"=(match(table_stat %>% pull(x), levels(table[,x]))+0.75*((match(table_stat$group1, levels(table[,group]))-0.5)/length(levels(table[,group]))-0.5)), |
|
|
|
|
|
"xmax"=match(table_stat %>% pull(x), unique(table[,x]))+0.75*((match(table_stat$group2, levels(table[,group]))-0.5)/length(levels(table[,group]))-0.5) |
|
|
|
|
|
|
|
|
"xmin"=(match(table_stat %>% pull(x), levels(table[,x]))+dodge*((match(table_stat$group1, levels(table[,group]))-0.5)/length(levels(table[,group]))-0.5)), |
|
|
|
|
|
"xmax"=match(table_stat %>% pull(x), unique(table[,x]))+dodge*((match(table_stat$group2, levels(table[,group]))-0.5)/length(levels(table[,group]))-0.5) |
|
|
) %>% rename("x"="x.temp") |
|
|
) %>% rename("x"="x.temp") |
|
|
}else{ |
|
|
}else{ |
|
|
t<-tibble("y.position"=merge(table_stat, agg ,sort=F)[,"max"]+diff(range(table[value.var], na.rm = T))*bracket.offset, |
|
|
t<-tibble("y.position"=merge(table_stat, agg ,sort=F)[,"max"]+diff(range(table[value.var], na.rm = T))*bracket.offset, |
|
|