Title: | Significance Brackets for 'ggplot2' |
---|---|
Description: | Enrich your 'ggplots' with group-wise comparisons. This package provides an easy way to indicate if two groups are significantly different. Commonly this is shown by a bracket on top connecting the groups of interest which itself is annotated with the level of significance (NS, *, **, ***). The package provides a single layer (geom_signif()) that takes the groups for comparison and the test (t.test(), wilcox.text() etc.) as arguments and adds the annotation to the plot. |
Authors: | Constantin Ahlmann-Eltze [aut, cre, ctb] (<https://orcid.org/0000-0002-3762-068X>, @const_ae), Indrajeet Patil [aut, ctb] (<https://orcid.org/0000-0003-1995-6531>, @patilindrajeets) |
Maintainer: | Constantin Ahlmann-Eltze <[email protected]> |
License: | GPL-3 | file LICENSE |
Version: | 0.6.4.9000 |
Built: | 2024-11-09 04:38:24 UTC |
Source: | https://github.com/const-ae/ggsignif |
Create significance layer
stat_signif( mapping = NULL, data = NULL, position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, comparisons = NULL, test = "wilcox.test", test.args = NULL, annotations = NULL, map_signif_level = FALSE, y_position = NULL, xmin = NULL, xmax = NULL, margin_top = 0.05, step_increase = 0, tip_length = 0.03, size = 0.5, textsize = 3.88, family = "", vjust = 0, parse = FALSE, manual = FALSE, orientation = NA, ... ) geom_signif( mapping = NULL, data = NULL, stat = "signif", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, comparisons = NULL, test = "wilcox.test", test.args = NULL, annotations = NULL, map_signif_level = FALSE, y_position = NULL, xmin = NULL, xmax = NULL, margin_top = 0.05, step_increase = 0, extend_line = 0, tip_length = 0.03, size = 0.5, textsize = 3.88, family = "", vjust = 0, parse = FALSE, manual = FALSE, orientation = NA, ... )
stat_signif( mapping = NULL, data = NULL, position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, comparisons = NULL, test = "wilcox.test", test.args = NULL, annotations = NULL, map_signif_level = FALSE, y_position = NULL, xmin = NULL, xmax = NULL, margin_top = 0.05, step_increase = 0, tip_length = 0.03, size = 0.5, textsize = 3.88, family = "", vjust = 0, parse = FALSE, manual = FALSE, orientation = NA, ... ) geom_signif( mapping = NULL, data = NULL, stat = "signif", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, comparisons = NULL, test = "wilcox.test", test.args = NULL, annotations = NULL, map_signif_level = FALSE, y_position = NULL, xmin = NULL, xmax = NULL, margin_top = 0.05, step_increase = 0, extend_line = 0, tip_length = 0.03, size = 0.5, textsize = 3.88, family = "", vjust = 0, parse = FALSE, manual = FALSE, orientation = NA, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
comparisons |
A list of length-2 vectors. The entries in the vector are either the names of 2 values on the x-axis or the 2 integers that correspond to the index of the columns of interest. |
test |
the name of the statistical test that is applied to the values of
the 2 columns (e.g. |
test.args |
additional arguments for the test method |
annotations |
character vector with alternative annotations, if not null test is ignored |
map_signif_level |
Boolean value, if the p-value are directly written as
annotation or asterisks are used instead. Alternatively one can provide a
named numeric vector to create custom mappings from p-values to annotation:
For example: |
y_position |
numeric vector with the y positions of the brackets |
xmin , xmax
|
numeric vector with the positions of the left and right sides of the brackets, respectively |
margin_top |
numeric vector how much higher that the maximum value that bars start as fraction of total height |
step_increase |
numeric vector with the increase in fraction of total height for every additional comparison to minimize overlap. |
tip_length |
numeric vector with the fraction of total height that the bar goes down to indicate the precise column |
size |
change the width of the lines of the bracket |
textsize |
change the size of the text |
family |
change the font used for the text |
vjust |
move the text up or down relative to the bracket |
parse |
If |
manual |
Boolean flag that indicates that the parameters are provided with a data.frame. This option is necessary if one wants to plot different annotations per facet. |
orientation |
The orientation of the layer. The default (‘NA’) automatically determines the orientation from the aesthetic mapping. In the rare event that this fails it can be given explicitly by setting 'orientation' to either "x" or "y" |
... |
other arguments passed on to |
stat |
The statistical transformation to use on the data for this
layer, either as a |
extend_line |
Numeric that allows to shorten (negative values) or extend (positive value) the horizontal line between groups for each comparison; defaults to 0. |
## Not run: library(ggplot2) library(ggsignif) ggplot(mpg, aes(class, hwy)) + geom_boxplot() + geom_signif(comparisons = list( c("compact", "pickup"), c("subcompact", "suv") )) ggplot(mpg, aes(class, hwy)) + geom_boxplot() + geom_signif( comparisons = list( c("compact", "pickup"), c("subcompact", "suv") ), map_signif_level = function(p) sprintf("p = %.2g", p) ) ggplot(mpg, aes(class, hwy)) + geom_boxplot() + geom_signif( annotations = c("First", "Second"), y_position = c(30, 40), xmin = c(4, 1), xmax = c(5, 3) ) ## End(Not run)
## Not run: library(ggplot2) library(ggsignif) ggplot(mpg, aes(class, hwy)) + geom_boxplot() + geom_signif(comparisons = list( c("compact", "pickup"), c("subcompact", "suv") )) ggplot(mpg, aes(class, hwy)) + geom_boxplot() + geom_signif( comparisons = list( c("compact", "pickup"), c("subcompact", "suv") ), map_signif_level = function(p) sprintf("p = %.2g", p) ) ggplot(mpg, aes(class, hwy)) + geom_boxplot() + geom_signif( annotations = c("First", "Second"), y_position = c(30, 40), xmin = c(4, 1), xmax = c(5, 3) ) ## End(Not run)