pretty_p: Format p values for display

View source: R/prety-p.R

pretty_pR Documentation

Format p values for display

Description

Format p values for display

Usage

pretty_p(
  p,
  p_digits,
  small_p_format = c("<", "E", "x10", "plotmath", "html"),
  small_p_cutoff = 10^-p_digits,
  sig_fig = FALSE,
  n_sig_fig = 2
)

Arguments

p

p value to format

p_digits

number of digits to display

small_p_format

format used to display p values below a threshold

small_p_cutoff

cutoff for displaying alternative formatting

sig_fig

whether to use significant figures when rounding p values

n_sig_fig

number of significant figures to use

Value

formatted p value

Examples

p_values <- 10 ^ seq(-1, -6, -1)
# Format p values as for example 1.0x10^-4
pretty_p(p_values, p_digits = 3, small_p_format = "x10")
# Format p values for use on a graph
x <- rlnorm(100, 3, 1)
y <- rlnorm(100, 4, 1)
p <- wilcox.test(x, y)$p.value
p_formatted <- pretty_p(p, p_digits = 3, small_p_format = "plotmath")
boxplot(x, y, ylim = c(0, max(c(x, y)) + 100))
text(1.5, max(c(x, y) + 50), parse(text = paste0("p == ", p_formatted)))

NikNakk/tableone documentation built on March 22, 2022, 1:19 p.m.