Browse Source

Correcting bugs.

main
marcelcosta 1 year ago
parent
commit
0cb487caa4
1 changed files with 7 additions and 7 deletions
  1. +7
    -7
      R/ggstats_add_xy.R

+ 7
- 7
R/ggstats_add_xy.R

@ -5,26 +5,26 @@ ggstats_add_xy<-function(table_stat, table, xcol=NULL, group, y="max", bracket.o
x<-colnames(table_stat)[1]
}else{x<-xcol}
if(!is.null(group)){table[,group]<-as.factor(table[,group])}
table[,x]<-as.factor(table[,x])
if(!is.null(group)){table[,group]<-as.factor(pull(table,group))}
table[,x]<-as.factor(pull(table,x))
if (is.null(exclude_group)){
table_agg<-table %>% group_by(.data[[x]])
}else{
table_agg<-table %>% group_by(.data[[x]], .data[[exclude_group]])
}
if (y == "max"){
agg<-table_agg %>% summarise(max=max(.data[[value.var]]))
if(!is.na(exclude_group)){agg<-table_agg %>% group_by(.data[[exclude_group]]) %>% summarise(max=max(.data[[value.var]]))}
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))}
}else if (y == "mean"){
agg<-table %>% group_by(.data[[x]],.data[[group]]) %>% summarise(mean=mean(.data[[value.var]])) %>% 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))
colnames(agg)[1]<-x
}else if (y == "mean+sd"){
agg<-table %>% group_by(.data[[x]],.data[[group]]) %>% summarise(mean=mean(.data[[value.var]])+sd(.[[value.var]])) %>% spread(group, mean)
agg<-table %>% group_by(.data[[x]],.data[[group]]) %>% summarise(mean=mean(.data[[value.var]], na.rm=T)+sd(.[[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))
colnames(agg)[1]<-x
}else if (y == "mean+sem"){
agg<-table %>% group_by(.data[[x]],.data[[group]]) %>% summarise(mean=mean(.data[[value.var]])+sem(.[[value.var]])) %>% spread(group, mean)
agg<-table %>% group_by(.data[[x]],.data[[group]]) %>% summarise(mean=mean(.data[[value.var]], na.rm=T)+sem(.[[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))
colnames(agg)[1]<-x
}

Loading…
Cancel
Save