drawViolinPlot: draw a violin plot

View source: R/np_plotting_functions.R

drawViolinPlotR Documentation

draw a violin plot

Description

Produce a violin plot with optional box plot and strip plot overlays

Usage

drawViolinPlot(
  x,
  groups,
  at = seq(1, length(levels(groups))),
  h = NULL,
  plotColors = basicTheme$plotColors,
  sidePlot = FALSE,
  borderCol = plotColors$lines,
  borderWidth = 1,
  fill = plotColors$fill,
  width = 1,
  trimViolins = TRUE,
  samplePoints = NULL
)

Arguments

x

numeric; A vector of numeric values that will be subset and formated by the factor(s) in by.

groups

factor; A factor used to subset x to draw the violins.

at

numeric; a numeric vector of where each factor level should be plotted

h

numeric; Bandwidth for the kernel density estimates. Will cycle over values if multiple bandwidths are given

plotColors

list; a named list of vectors of colors that set the color options for all NicePlot functions.

sidePlot

logical; If TRUE, the x and y ploting axis are swapped

borderCol

R color string; Color of the border of the violins

borderWidth

numeric; Thickness of the violin borders (lwd)

fill

R color string; Color of the interior of the violins

width

numeric; Relative width of the violins. A value of 1 will cause the violins to cover their entire lane and potentially just touch.

trimViolins

logical; Should the violins be truncated at the edges of the data range.

samplePoints

integer; The number of points used to draw each side of the violin. This is generally obtained from theme$curvePoints.

Details

This uses bkde from the KernSmooth package to calculated kernel density estimates and estimate the optimal bandwidth h setting. This data is then used to draw a violin plot with an optional boxplot drawn as an overlay to better characterize the quartile distribution. Likewise, a strip chart of individual data points can be added on top of these two plots to full characterize the data distribution. This uses niceBox to handle the box plot and strip chart overlays.

See Also

niceVio, bkde, dpik


ZachHunter/NicePlots.R documentation built on Sept. 23, 2023, 4:04 a.m.