cond.boxplots: Bivariate Conditional Boxplots

View source: R/02_data_preparation.R

cond.boxplotsR Documentation

Bivariate Conditional Boxplots

Description

The cond.boxplots function draws, within a single panel, conditional boxplots (i.e. a plot of a continuous Y variable against one or several categorical X(s) variable(s) (factor), or discretized numeric variable(s)) in order to explore bivariate relationships and assess heteroscedasticity.
If some of the X variables are quantitative (numeric), they will consequently be transformed into factors and discretized into a given number of classes, set approximately by the N parameter. This factorisation is required because boxplots are not meant to plot two quantitative variables (without factorisation, the function would plot as many boxplots as there are values in X).

Usage

cond.boxplots(
  dataset,
  Y,
  Xs,
  outlier,
  N = 6,
  MAR = c(2.2, 2.1, 0.5, 1.7),
  CEX.LAB = 0.9,
  FONT.LAB = 2,
  BTY = "n",
  FG = "gray35",
  COL.AXIS = "gray35",
  COL.LAB = "gray20",
  CEX.PAR = 0.8,
  TCL = -0.3,
  MGP = c(1.2, 0.4, 0.2),
  OMA = c(1, 0, 0, 0),
  TYPE = "n",
  BORDER = "moccasin",
  COL = "gray50",
  LTY = 1,
  STAPLEWEX = 0,
  WHISKLWD = 2,
  BOXWEX = 0.5,
  BOXLWD = 0.1,
  MEDLWD = 2.6,
  PCH = 19,
  ...
)

Arguments

dataset

The input data.frame containing the variables to plot (both the Y and the X(s)). Must only contain numeric or factor variables!

Y

The number of the column of dataset containing the variable to be plotted as Y. This parameter should be specified as an integer. For instance, if the variable to be used as Y is called "blip" and is the second column of the dataset, the Y parameter should be 2 (and NOT "two", dataset$blip, or dataset[,2]).

Xs

The numbers of the columns to be plotted as Xs (e.g. 4:10, if all the columns from the fourth to the tenth are to be plotted against Y).

outlier

Logical (TRUE or FALSE). Should outliers be plotted or not?

N

Integer. The number of bins on X. Default is 6.

MAR

A numerical vector of the form c(bottom, left, top, right) which gives the number of lines of margin to be specified on the four sides of the plot. The default is c(2.2,2.1,0.5,1.7).

CEX.LAB

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

FONT.LAB

The font to be used for x and y labels.

BTY

A character string which determined the type of box which is drawn about plots. If BTY is one of "o", "l", "7", "c", "u", or "]" the resulting box resembles the corresponding upper case letter. A value of "n" suppresses the box (the default).

FG

The color to be used for the foreground of plots. This is the default color used for things like axes and boxes around plots (defaults to "gray35").

COL.AXIS

The color to be used for axis annotation. Defaults to "gray35".

COL.LAB

The color to be used for x and y labels. Defaults to "gray20".

CEX.PAR

A numerical value giving the amount by which plotting text and symbols should be magnified relative to the default (for par, the panel manager). This starts as 1 when a device is opened, and is reset when the layout is changed, e.g. by setting mfrow. Defaults to 0.8.

TCL

The length of tick marks as a fraction of the height of a line of text. The default value is -0.3.

MGP

The margin line (in mex units) for the axis title, axis labels and axis line. Note that mgp[1] affects title whereas mgp[2:3] affect axis. The default is c(1.2, 0.4, 0.2).

OMA

A vector of the form c(bottom, left, top, right) giving the size of the outer margins in lines of text.

TYPE

The type of boxplot to draw. Default is "n".

BORDER

An optional vector of colors for the outlines of the boxplots. The values in border are recycled if the length of border is less than the number of plots. Default is "lightcoral".

COL

If col is non-null it is assumed to contain colors to be used to colour the bodies of the boxplots. Default is "moccasin".

LTY

The line type. Line types can either be specified as an integer (0=blank, 1=solid (default), 2=dashed, 3=dotted, 4=dotdash, 5=longdash, 6=twodash) or as one of the character strings "blank", "solid", "dashed", "dotted", "dotdash", "longdash", or "twodash", where "blank" uses ‘invisible lines’ (i.e., does not draw them).

STAPLEWEX

Staple line width expansion, proportional to box width. Default is 0.

WHISKLWD

Whisker line width expansion. Default is 2.

BOXWEX

A scale factor to be applied to all boxes. When there are only a few groups, the appearance of the plot can be improved by making the boxes narrower. Default is 0.7.

BOXLWD

Width of boxplot outer lines. Default is 0.1.

MEDLWD

Width of the median line. Default is 2.6.

PCH

The type of points to be drawn for outliers. Default is 19. See points for possible values and their interpretation.

...

Any other graphical parameter of boxplot().

Value

A panel of conditional boxplots.

Examples

cond.boxplots(dataset = iris, Y = 1, Xs = 2:5, outlier = TRUE)

mrelnoob/jk.dusz.tarping documentation built on July 31, 2023, 9:19 a.m.