viol {paleoDiv}R Documentation

Generate a violin plot

Description

Generate a violin plot

Usage

viol(
  x,
  pos = 0,
  x2 = NULL,
  stat = density,
  dscale = 1,
  cutoff = range(x),
  horiz = TRUE,
  add = TRUE,
  lim = cutoff,
  xlab = "",
  ylab = "",
  fill = "grey",
  col = "black",
  lwd = 1,
  lty = 1,
  ...
)

Arguments

x

Variable for which to plot violin.

pos

Position at which to place violin in the axis perpendicular to x. Defaults to 0

x2

Optional variable to use instead of x as input variable for the violin plot. If x2 is set, the function (default: density()) used to calculate the plotting statistic is run on x2 instead of x, but the results are plotted at the corresponding x values.

stat

The plotting statistic. Details to the density() function, as in a standard violin plot, but can be overridden with another function that can take x or x2 as its first argument. Stat can also be a numeric vector of the same length as x, in which case the values in this vectors are used instead of the function output and plotted against x as an independent variable.

dscale

The scale to apply to the values for density (or another plotting statistic). Defaults to 1, but adjustment may be needed depending on the scale of the plot the violin is to be added to.

cutoff

Setting for cropping the violin. Can be either a single value, in which case the input is interpreted as number of standard deviations from the mean, or a numeric vector of length 2, giving the lower and upper cutoff value directly.

horiz

Logical indicating whether to plot horizontally (defaults to TRUE) or vertically

add

Logical indicating whether to add to an existing plot (defaults to TRUE) or generate a new plot.

lim

Limits (in the dimensions of x) used for plotting, if add==FALSE. Defaults to cutoff, but can be manually set as a numeric vector of length 2, giving the lower and upper limits of the plot.

xlab

x axis label

ylab

y axis label

fill

Fill color for the plotted violin

col

Line color for the plotted violin

lwd

Line width for the plotted violin

lty

Line width for the plotted violin

...

Other arguments to be passed on to function in parameter stat

Details

Viol provides a versatile function for generating violin plots and adding them to r base graphics. The default plotting statistic is density(), resulting in the standard violin plot. However, density can be overridden by entering any function that can take x or x2 as its first argument, or any numeric vector containing the data to be plotted, as long as this vector is the same length as x.

Value

A violin plot and a data.frame containing the original and modified plotting statistic and independent variable against which it is plotted.

Examples

viol(x=c(1,2,2,2,3,4,4,3,2,2,3,3,4,5,3,3,2,2,1,6,7,6,9),pos=1, add=FALSE)
viol(c(1:10), width=9, stat=rmean, pos=0, add=FALSE)
viol(c(1:10), stat=c(11:20), pos=0, add=FALSE)

[Package paleoDiv version 0.3.0 Index]