pplot: pplot

View source: R/plot.R

pplotR Documentation

pplot

Description

A paired plot for continuous data. Draws a dot plot with points jittered to the left and right about the group position. Jittering is done with beeswarm; however, the original data values are used instead of using the slight adjustments made by beeswarm. Additionally, a two-sample wilcox.test test is performed on each pair by default, but the test and assumptions may be controlled using test and args.test arguments, respectively; see examples.

Usage

pplot(x, ...)

## S3 method for class 'formula'
pplot(formula, data, ...)

## Default S3 method:
pplot(
  x,
  at = seq_along(x),
  pad = 0.05,
  test = wilcox.test,
  args.test = list(),
  col = 1:2,
  pch = par("pch"),
  cex = par("cex"),
  args.beeswarm = list(),
  names,
  quantiles = NULL,
  pch.quantiles = rep_len(16L, length(quantiles)),
  xlab = NULL,
  ylab = NULL,
  legend.text = NULL,
  ...
)

Arguments

x

for the default method, a list of groups each having a list of length 2 of data values

...

for the formula method, named arguments to be passed to the default method

for the default method, additional arguments passed to tplot or graphical parameters passed to par

formula

a formula, such as y ~ group1 + group2, where y is a numeric vector of data values to be split into n groups (group1), each group split into at most two groups (group2)

data

a data frame (or list) from which the variables in formula should be taken

at

the x-axis group positions

pad

the padding between at for each group and the points

test

logical or function; if TRUE, a wilcox.test p-value is added for each group

alternatively, a function (or function name as a character string) can be used, e.g., test = t.test or function(x, y) t.test(x, y); note that if test is a function, it must have at least two arguments with the two groups of data; see examples

args.test

a named list of arguments passed to test

col, pch, cex

color, plotting character, and character expansion vectors, each may be length 1, 2, or total number of groups to be plotted, recycled as needed

args.beeswarm

a named list of arguments passed to beeswarm to override defaults

names

group labels having the same length as l

quantiles

optional probabilities passed to quantile to show for each group

pch.quantiles

plotting character for each quantile

xlab, ylab

x- and y-axis labels

legend.text

group labels of length 2

Examples

## basic usage
pplot(split(mtcars$mpg, mtcars$vs))
pplot(mpg ~ vs, mtcars)


set.seed(1)
x <- lapply(1:5, function(x) list(rnorm(20, 0, x), rnorm(20, 0, x)))

pplot(x)
pplot(x[1], ylim = c(-3, 3))
pplot(x, test = t.test, args.test = list(paired = TRUE))
pplot(x, col = rep(2:6, each = 2), pch = c(1, 16), legend.text = c('+', '-'))
pplot(x, quantiles = 0.5, legend.text = c('+', '-'))


## pplot returns the object returned by test
pv <- pplot(
  x, quantiles = c(0.25, 0.5, 0.75), pch.quantiles = c(6, 18, 2),
  legend.text = c('+', '-'), pad = 0.1, pch = 16, bty = 'l',
  names = paste('group', 1:5), las = 1
)
sapply(pv, function(x) x$p.value)


## use a custom test function
pplot(x, test = function(x, y) cor.test(x, y, method = 'spearman'))

moods <- function(x, y) rawr::moods.test(list(x, y))
pplot(x, test = moods)
sapply(x, function(y) do.call('moods', y)$p.value)


## formula method
pplot(mpg ~ gear + am, mtcars)
pplot(mpg ~ gear + vs, mtcars, xlab = 'Gears', legend.text = c('V', 'S'))


raredd/rawr documentation built on March 4, 2024, 1:36 a.m.