gg_pval_hist: Create p-value histogram

Description Usage Arguments Details Value Examples

View source: R/gg-pval-hist.R

Description

Use ggplot2::geom_histogram() to create a histogram of p-values but with better binwidths and axis limits.

Usage

1
2
3
gg_pval_hist(p_values, binwidth = 0.05)

geom_pval_hist(mapping = NULL, ..., binwidth = 0.05)

Arguments

p_values

Vector of p-values.

binwidth

Binwidth of the histogram. A sensible choice is to use the significance cut-off so that the height of the first bar corresponds to the number of significant cases. Default: 0.05.

mapping

Set of aesthetic mappings created by aes() or 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.

...

Arguments passed on to ggplot2::geom_histogram

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)).

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

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().

bins

Number of bins. Overridden by binwidth. Defaults to 30.

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". See the Orientation section for more detail.

stat

Use to override the default connection between geom_histogram()/geom_freqpoly() and stat_bin().

Details

By default, ggplot2::geom_histogram() centers the first and last bins of the histogram on the x-axis lower and upper limits, respectively. In case of p-values, which lie in the interval [0, 1], it makes more sense to set the boundaries of the first and last bins at 0 and 1. The binwidths are also set at 0.05, commonly used as a cut-off for significance, so that the height of the first bar represents the number of p-values lying between 0 and 0.05, i.e. the number of cases that would be deemed significant.

Value

A ggplot object.

Examples

1
2
3
4
5
6
7
pvals <- runif(n = 1000, min = 0, max = 1)
gg_pval_hist(pvals)

## Using a data.frame in combination with `ggplot`
library(ggplot2)
df <- data.frame(pvalue = runif(1000))
ggplot(df, aes(pvalue)) + geom_pval_hist()

milanmlft/MMmotley documentation built on Feb. 4, 2022, 7:42 a.m.