Reppo for internal functions.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
2.0 KiB

\name{ggstats_add_xy}
\alias{ggstats_add_xy}
\title{ggstats_add_xy}
\usage{
ggstats_add_xy(table_stat, table, group, xcol=NULL, y="max", bracket.offset=0.05, bracket.inspace=0.05, exclude_group=NULL)
}
\arguments{
\item{table_stat}{A table generated by a rstatix funcion such as t_test() or wilcox_test().}
\item{table}{The original table that was introduced to ggplot.}
\item{xcol}{The X-axis variable. If null (the default), the function will pick the first column. This is intended when exclude_group is null.}
\item{group}{The grouping variable. If null, the function will emulate the add_y_position function instead of add_xy_position.}
\item{y}{The algorithm used to calculate the y height. Is useful to adapt to plots that show all events, bars with the mean, etc... Options are "max" (default), "mean", "mean+sd", "mean+sem".}
\item{bracket.offset}{Increasing this parameter incresases the y position of the brackets.}
\item{bracket.inspace}{Increasing this parameter increases the space between brackets.}
\item{exclude_group}{Variable(s) that will not be grouped. This aims to preserve the variable in order to facet.}
}
\description{
Generates a table with the coordinates that is required by the ggpubr function "stat_pvalue_manual".
}
\examples{
library(tidyverse)
library(ggpubr)
library(rstatix)
df<-data.frame("pats"=paste0("PAT", 1:20), "Group"=rep(c("A","B"),each=10),"CytA"=rnorm(20,5), "CytB"=rnorm(20,5),"CytC"=c(rnorm(5,10),rnorm(5,10),rnorm(5,5),rnorm(5,5)),"CytD"=rnorm(20,5),"CytE"=c(rnorm(5,10),rnorm(5,5),rnorm(5,10),rnorm(5,5)),"CytF"=rnorm(20,5),"CytG"=c(rnorm(5,5),rnorm(5,5),rnorm(5,7),rnorm(5,7)))
mdf<-gather(df, "Cytokine","Value",-c(pats,Group))
g<-ggplot(mdf, aes(Cytokine, Value, color=Group))+
geom_boxplot()+
geom_point(position=position_dodge(width = 0.75))
stat.test<-mdf \%>\% group_by(Cytokine) \%>\% t_test(Value~Group)
g+stat_pvalue_manual(ggstats_add_xy(stat.test, mdf, "Cytokine","Group"), label = "p", tip.length = 0.02, hide.ns = T)
}