vioplot2: violin plot

Description Usage Arguments Details Author(s) References See Also Examples

View source: R/vioplot2.R

Description

Produce violin plot(s) of the given (grouped) values.

Modified by Xiangchun LI to process whose input is a data frame with multiple variables.

Usage

1
2
3
4
vioplot(datas, range=1.5, h, ylim, names, horizontal=FALSE, 
  col="magenta", border="black", lty=1, lwd=1, rectCol="black", 
  colMed="white", pchMed=19, at, add=FALSE, wex=0.8, 
  drawRect=TRUE, box=TRUE, axes=TRUE, color.brewer=TRUE)

Arguments

datas

a data frame or a list with multiple variables

...

additional data vectors

range

a factor to calculate the upper/lower adjacent values

h

the height for the density estimator, if omit as explained in sm.density, h will be set to an optimum

ylim

y limits

names

one label, or a vector of labels for the datas must match the number of datas given

col, border, lty, lwd

Graphical parameters for the violin passed to lines and polygon

rectCol, colMed, pchMed

Graphical parameters to control the look of the box

drawRect

logical. the box is drawn if TRUE.

at

position of each violin. Default to 1:n

add

logical. if FALSE (default) a new plot is created

wex

relative expansion of the violin.

horizontal

logical. horizontal or vertical violins

box

logical. draw box or not

axes

logical. display axes or not

color.brewer

logical. if TRUE use automatically use color scheme from package RColorBrewer

Details

A violin plot is a combination of a box plot and a kernel density plot. Specifically, it starts with a box plot. It then adds a rotated kernel density plot to each side of the box plot.

Author(s)

Daniel Adler dadler@uni-goettingen.de

Romain Francois francoisromain@free.fr ; http://francoisromain.free.fr : horizontal violins and additionnal graphical parameters

References

Hintze, J. L. and R. D. Nelson (1998). Violin plots: a box plot-density trace synergism. The American Statistician, 52(2):181-4.

See Also

boxplot sm

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
###############Examples provided by Xiangchun LI################
A=rnorm(100, 1)
B=rnorm(100, 1.3)
C=rnorm(100, 1.5)
D=rnorm(100, 1.6)
E=rnorm(100, 1.8)
F=rnorm(100, 0.8)
data=data.frame(A, B, C, D, E, F)
vioplot2(data)
###############End of examples provided by Xiangchun LI################

  # box- vs violin-plot 
  par(mfrow=c(2,1))
  mu<-2
  si<-0.6
  bimodal<-c(rnorm(1000,-mu,si),rnorm(1000,mu,si)) 
  uniform<-runif(2000,-4,4)
  normal<-rnorm(2000,0,3)
  vioplot(bimodal,uniform,normal)
  boxplot(bimodal,uniform,normal)
  
  # add to an existing plot
  x <- rnorm(100)
  y <- rnorm(100)
  plot(x, y, xlim=c(-5,5), ylim=c(-5,5))
  vioplot(x, col="tomato", horizontal=TRUE, at=-4, add=TRUE,lty=2, rectCol="gray")
  vioplot(y, col="cyan", horizontal=FALSE, at=-4, add=TRUE,lty=2)

lixiangchun/lxctk documentation built on May 21, 2019, 6:44 a.m.