vioplotx: Enhanced Violin Plot

Description Usage Arguments Examples

Description

Produce violin plot(s) of the given (grouped) values with enhanced annotation and colour per group. Builds upon vioplot and intended to function in largely the same way, with added customisation possible with colours for each aspect of the violin, boxplot, and separate violins. This supports input of data as a list or formula, being backwards compatible with vioplot and taking input in a formula as used for boxplot.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## S3 method for class 'formula'
vioplotx(formula, data = NULL, ..., names = NULL,
  na.action = NULL)

## Default S3 method:
vioplotx(x, ..., data = NULL, range = 1.5, h = NULL,
  ylim = NULL, names = NULL, horizontal = FALSE, col = "grey50",
  border = "black", lty = 1, lwd = 1, rectCol = "black",
  lineCol = "black", pchMed = 19, colMed = "white", colMed2 = "grey 75",
  at, add = FALSE, wex = 1, drawRect = TRUE, areaEqual = FALSE,
  main = NA, sub = NA, xlab = NA, ylab = NA, cex = 1, cex.axis = 1,
  cex.names = NULL, cex.lab = 1, cex.main = 1, cex.sub = 1,
  yaxt = "s", ylog = FALSE, log = "", logLab = c(1, 2, 5),
  na.action = NULL, na.rm = T, side = "both", plotCentre = "point")

Arguments

x

for specifying data from which the boxplots are to be produced. Either a numeric vector, or a single list containing such vectors. Additional unnamed arguments specify further data as separate vectors (each corresponding to a component boxplot). NAs are allowed in the data.

...

additional data vectors or forumla parameters.

formula

a formula, such as y ~ grp, where y is a numeric vector of data values to be split into groups according to the grouping variable grp (usually a factor).

data

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

names

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

na.action

a function which indicates what should happen when the data contain NAs. The default is to ignore missing values in either the response or the group.

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

horizontal

logical. horizontal or vertical violins

col

Graphical parameter for fill colour of the violin(s) polygon. NA for no fill colour. If col is a vector, it specifies the colour per violin, and colours are reused if necessary.

border

Graphical parameters for the colour of the violin border passed to lines. NA for no border. If border is a vector, it specifies the colour per violin, and colours are reused if necessary.

lty, lwd

Graphical parameters for the violin passed to lines and polygon

rectCol

Graphical parameters to control fill colour of the box. NA for no fill colour. If col is a vector, it specifies the colour per violin, and colours are reused if necessary.

lineCol

Graphical parameters to control colour of the box outline and whiskers. NA for no border. If lineCol is a vector, it specifies the colour per violin, and colours are reused if necessary.

pchMed

Graphical parameters to control shape of the median point. If pchMed is a vector, it specifies the shape per violin.

colMed, colMed2

Graphical parameters to control colour of the median point. If colMed is a vector, it specifies the colour per violin. colMed specifies the fill colour in all cases unless pchMed is 21:25 in which case colMed is the border colour and colMed2 is the fill colour.

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. If wex is a vector, it specifies the area/width size per violin and sizes are reused if necessarydocu.

drawRect

logical. The box is drawn if TRUE.

areaEqual

logical. Density plots checked for equal area if TRUE. wex must be scalar, relative widths of violins depend on area.

main, sub, xlab, ylab

graphical parameters passed to plot.

cex

A numerical value giving the amount by which plotting text should be magnified relative to the default.

cex.axis

The magnification to be used for y axis annotation relative to the current setting of cex.

cex.names

The magnification to be used for x axis annotation relative to the current setting of cex. Takes the value of cex.axis if not given.

cex.lab

The magnification to be used for x and y labels relative to the current setting of cex.

cex.main

The magnification to be used for main titles relative to the current setting of cex.

cex.sub

The magnification to be used for sub-titles relative to the current setting of cex.

yaxt

A character which specifies the y axis type. Specifying "n" suppresses plotting.

ylog

A logical value (see log in plot.default). If TRUE, a logarithmic scale is in use (e.g., after plot(*, log = "y")). For a new device, it defaults to FALSE, i.e., linear scale.

log

Logarithmic scale if log = "y" or TRUE. Invokes ylog = TRUE.

logLab

Increments for labelling y-axis on log-scale, defaults to numbers starting with 1, 2, 5, and 10.

na.rm

logical value indicating whether NA values should be stripped before the computation proceeds. Defaults to TRUE.

side

defaults to "both". Assigning "left" or "right" enables one sided plotting of violins. May be applied as a scalar across all groups.

plotCentre

defaults to "points", plotting a central point at the median. If "line" is given a median line is plotted (subject to side) alternatively.

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#generate example data
data_one <- rnorm(100)
data_two <- rnorm(50, 1, 2)

#generate violin plot with similar functionality to vioplot
vioplotx(data_one, data_two, col="magenta")

#note vioplox defaults to a greyscale plot
vioplotx(data_one, data_two)

#colours can be customised separately, with axis labels, legends, and titles
vioplotx(data_one, data_two, col=c("red","blue"), names=c("data one", "data two"),
   main="data violin", xlab="data class", ylab="data read")
legend("topleft", fill=c("red","blue"), legend=c("data one", "data two"))

#colours can be customised for the violin fill and border separately
vioplotx(data_one, data_two, col="grey85", border="purple", names=c("data one", "data two"),
   main="data violin", xlab="data class", ylab="data read")

#colours can also be customised for the boxplot rectange and lines (border and whiskers)
vioplotx(data_one, data_two, col="grey85", rectCol="lightblue", lineCol="blue",
   border="purple", names=c("data one", "data two"),
   main="data violin", xlab="data class", ylab="data read")

#these colours can also be customised separately for each violin
vioplotx(data_one, data_two, col=c("skyblue", "plum"), rectCol=c("lightblue", "palevioletred"),
   lineCol="blue", border=c("royalblue", "purple"), names=c("data one", "data two"),
   main="data violin", xlab="data class", ylab="data read")

#this applies to any number of violins, given that colours are provided for each
vioplotx(data_one, data_two, rnorm(200, 3, 0.5), rpois(200, 2.5),  rbinom(100, 10, 0.4),
   col=c("red", "orange", "green", "blue", "violet"),
   rectCol=c("palevioletred", "peachpuff", "lightgreen", "lightblue", "plum"),
   lineCol=c("red4", "orangered", "forestgreen", "royalblue", "mediumorchid"),
   border=c("red4", "orangered", "forestgreen", "royalblue", "mediumorchid"),
   names=c("data one", "data two", "data three", "data four", "data five"),
   main="data violin", xlab="data class", ylab="data read")

#The areaEqual parameter scales with width of violins
#Violins will have equal density area (including missing tails) rather than equal maximum width
vioplotx(data_one, data_two, areaEqual=TRUE)

vioplotx(data_one, data_two, areaEqual=TRUE,
   col=c("skyblue", "plum"), rectCol=c("lightblue", "palevioletred"),
   lineCol="blue", border=c("royalblue", "purple"), names=c("data one", "data two"),
   main="data violin", xlab="data class", ylab="data read")

vioplotx(data_one, data_two, rnorm(200, 3, 0.5), rpois(200, 2.5),  rbinom(100, 10, 0.4),
   areaEqual=TRUE, col=c("red", "orange", "green", "blue", "violet"),
   rectCol=c("palevioletred", "peachpuff", "lightgreen", "lightblue", "plum"),
   lineCol=c("red4", "orangered", "forestgreen", "royalblue", "mediumorchid"),
   border=c("red4", "orangered", "forestgreen", "royalblue", "mediumorchid"),
   names=c("data one", "data two", "data three", "data four", "data five"),
   main="data violin", xlab="data class", ylab="data read")

TomKellyGenetics/vioplotx documentation built on May 9, 2019, 4:53 p.m.