Title: | Annotate Statistical Tests for 'ggplot2' |
---|---|
Description: | Automatically performs desired statistical tests (e.g. wilcox.test(), t.test()) to compare between groups, and adds the resulting p-values to the plot with an annotation bar. Visualizing group differences are frequently performed by boxplots, bar plots, etc. Statistical test results are often needed to be annotated on these plots. This package provides a convenient function that works on 'ggplot2' objects, performs the desired statistical test between groups of interest and annotates the test results on the plot. |
Authors: | Jun Cheng [aut, cre] |
Maintainer: | Jun Cheng <[email protected]> |
License: | GPL-3 |
Version: | 0.2.5 |
Built: | 2025-02-27 03:46:32 UTC |
Source: | https://github.com/s6juncheng/ggpval |
Add p-values to ggplot objects.
add_pval( ggplot_obj, pairs = NULL, test = "wilcox.test", heights = NULL, barheight = NULL, textsize = 5, pval_text_adj = NULL, annotation = NULL, log = FALSE, pval_star = FALSE, plotly = FALSE, fold_change = FALSE, parse_text = NULL, response = "infer", ... )
add_pval( ggplot_obj, pairs = NULL, test = "wilcox.test", heights = NULL, barheight = NULL, textsize = 5, pval_text_adj = NULL, annotation = NULL, log = FALSE, pval_star = FALSE, plotly = FALSE, fold_change = FALSE, parse_text = NULL, response = "infer", ... )
ggplot_obj |
ggplot object |
pairs |
a list pairs of comparison. Groups indicated by integer numbers counted from left to right. e.g. list(c(1, 2), c(2, 3)) will compare first group with second, second group with third |
test |
character of statistical testing method. e.g. t.test, wilcox.test. Default wilcox.test |
heights |
integer or vector of integers. The heights of the p-value/annotation. Default maximum value from the data |
barheight |
tip bar height of the annotation. Default calculated by range_y / 20 |
textsize |
p-value/annotation text size |
pval_text_adj |
distance of p-value/annotation from annotation bar. Default barheight/2 |
annotation |
text to annotate. If specified, statistical test will not be done |
log |
whether y axis is log transformed. Default FALSE |
pval_star |
whether transform pval numbers to stars |
plotly |
set to TRUE if wrap the plot with 'ggploty' |
fold_change |
whether also compute and show fold changes. Default FALSE. |
parse_text |
whether parse the annotation text (NULL, TRUE, FALSE). If NULL, p-values will be parsed, text annotations will not. Default NULL. |
response |
the column that contains the data for statistical testing. Default infer from ggplot object. |
... |
additional arguments for statistical testing function (e.g. alternative = "less"). |
library(ggplot2) library(ggpval) data("PlantGrowth") plt <- ggplot(PlantGrowth, aes(group, weight)) + geom_boxplot() add_pval(plt, pairs = list(c(1, 3)), test='wilcox.test')
library(ggplot2) library(ggpval) data("PlantGrowth") plt <- ggplot(PlantGrowth, aes(group, weight)) + geom_boxplot() add_pval(plt, pairs = list(c(1, 3)), test='wilcox.test')