boxgroups: Multivariate and multi-subgroup boxplots

View source: R/boxgroups.R

boxgroupsR Documentation

Multivariate and multi-subgroup boxplots

Description

This function plots boxplots for various variables associated with ranges for various subgroups found into each variable

Usage

boxgroups(data,groups,box.opt=NULL,points.opt=NULL,box.width=0.3,
          group.plot=c("min","max"),group.plot.type=c("b","l"),
          names=NA,ticks=FALSE,x.gap=c(0,0),prop=FALSE,range=NA)

Arguments

data

A matrix or data frame to input.

groups

A vector of same length than the number of rows of data to distinguish subgroups for each variable.

box.opt

Optional. Plotting options to be passed for the boxplot function. Must be a list, the names being those of the parameter of this function.

points.opt

Optional. Plotting options to be passed for the points function. Must be a list, the names being those of the parameter of this function.

box.width

The relative width of the boxes, which also governs the gap between the box and the min-max lines of the variable.

group.plot

The type of points to be drawn to represent the variation of each subgroup in each variable. By default set to the minimal and maximal range of the subgroup to show its entire range.

group.plot.type

The type of plot to be drawn for the plot of each group alongside each boxplot. See plot argument of the plot.default function.

names

The names to be displayed under each boxplot + lines. Can be the names of the columns of data. If nothing is provided, will be alphabetical letters.

ticks

Logical. Should the ticks be displayed above each name? By default, ticks=FALSE.

x.gap

Gap between the plotted data and the left and right axes. Default set to c(0,0); if a single number is provided, automatically meant as left gap only.

prop

Logical. Do the boxplots need to be proportional with each other? By default, natural values are plotted (prop=FALSE).

range

If prop=TRUE, the range of values for rescaling the variables. By default set to 0-1.

Details

This function first plot the boxplots of the different variables inputted. Then, bars of each of the defined subgroups in each variable are plotted alongside each boxplot, showing desired values describing each subgroup variation within each variable (minimal and maximal values by default, but there can also be other ones detailed below). Graphical options to the boxplot and points formulas can be passed to customize the plot. There is also a way to rescale all variables in order to be able to compare the variables and the distribution of each subgroup.
There are various ways to describe the variation of each subgroup alongside the global variable boxplot, which are not exclusive. One needs to specify them in the group.plot argument with a character vector which can contain:

"min" and "max"

the extreme range, encompassing all points

"mean"

the average value of the whole subgroup

"median"

the median of the whole subgroup

"sd-X"

to obtain points from both sides of the mean by a proportion X (i.e., a number) of the standard deviation of the whole subgroup

"q-X"

to obtain the Xth percent quantile (i.e., a percentage)

"all"

to show all points of the subgroup

Examples

A<-runif(30,1,10)
B<-rexp(30)
C<-rnorm(30,0,1)
data<-data.frame(A=A,B=B,C=C)
groups<-sample(letters[1:4],30,replace=TRUE)
boxgroups(data=data,groups=groups,group.plot = c("all"))
boxgroups(data=data,groups=groups,points.opt=list("pch"=21,"col"=c("blue","red","green3","orange"),"bg"=c("blue","red","green3","orange"),"lwd"=2))


jacobmaugoust/ULT documentation built on May 16, 2023, 1:29 p.m.