geom_signif_wrapper: Wrapper for significance layer in 'ggsignif'

View source: R/geom_signif_wrapper.R

geom_signif_wrapperR Documentation

Wrapper for significance layer in ggsignif

Description

  • Modify y_position, margin_top, step_increase, tip_length to absolute position on y-axis.

  • Set map_signif_level, na.rm default TRUE.

Usage

geom_signif_wrapper(
  mapping = NULL,
  data = NULL,
  stat = "signif_wrapper",
  position = "identity",
  na.rm = TRUE,
  show.legend = NA,
  inherit.aes = TRUE,
  comparisons = NULL,
  test = "wilcox.test",
  test.args = NULL,
  annotations = NULL,
  map_signif_level = TRUE,
  y_position = NULL,
  xmin = NULL,
  xmax = NULL,
  margin_top = 1,
  step_increase = 0.4,
  extend_line = 0,
  tip_length = 0.1,
  size = 0.5,
  textsize = 3,
  family = "",
  vjust = 0.5,
  parse = FALSE,
  manual = FALSE,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)).

stat

The statistical transformation to use on the data for this layer. When using a ⁠geom_*()⁠ function to construct a layer, the stat argument can be used the override the default coupling between geoms and stats. The stat argument accepts the following:

  • A Stat ggproto subclass, for example StatCount.

  • A string naming the stat. To give the stat as a string, strip the function name of the stat_ prefix. For example, to use stat_count(), give the stat as "count".

  • For more information and other ways to specify the stat, see the layer stat documentation.

position

A position adjustment to use on the data for this layer. This can be used in various ways, including to prevent overplotting and improving the display. The position argument accepts the following:

  • The result of calling a position function, such as position_jitter(). This method allows for passing extra arguments to the position.

  • A string naming the position adjustment. To give the position as a string, strip the function name of the position_ prefix. For example, to use position_jitter(), give the position as "jitter".

  • For more information and other ways to specify the position, see the layer position documentation.

na.rm

If TRUE(the default), silently removes missing values.If FALSE, removes missing values with a warning.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders().

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. t.test, wilcox.test etc.). If you implement a custom test make sure that it returns a list that has an entry called p.value.

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: c("***"=0.001, "**"=0.01, "*"=0.05). Alternatively, one can provide a function that takes a numeric argument (the p-value) and returns a string.

y_position

numeric vector with the y positions of the brackets, absolute value relative to y-axis.

xmin

numeric vector with the positions of the left sides of the brackets

xmax

numeric vector with the positions of the right sides of the brackets

margin_top

numeric vector of the distance between brackets and maximum value of each plot (bar, box, violin...), absolute value relative to y-axis.

step_increase

numeric vector with the increase for each additional comparison, absolute value relative to y-axis.

extend_line

numeric that allows to shorten (negative values) or extend (positive value) the horizontal line between groups for each comparison; defaults 0.

tip_length

numeric vector with tip length for each bracket, absolute value relative to y-axis.

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 TRUE, the labels will be parsed into expressions and displayed as described in ?plotmath.

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.

...

other arguments passed on to layer. These are often aesthetics, used to set an aesthetic to a fixed value, like color = "red" or size = 3. They may also be parameters to the paired geom/stat.

Author(s)

  • Originally by Constantin Ahlmann-Eltze and Indrajeet Patil

  • Wrapped by Yujie Liu

Examples

## Not run: 
library(ggplot2)
library(ggsignif)
library(tinyfuncr)

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_wrapper(
    comparisons = list(
      c("compact", "pickup"),
      c("subcompact", "suv")
    ),
    annotations = c("First", "Second"),
    y_position = 40,
    step_increase = 2
  )

## End(Not run)

liuyujie0136/tinyfuncr documentation built on Dec. 13, 2024, 8:49 a.m.