box_mean_plot: Box plots of grouped data with optional mean value

View source: R/box_mean_plot.R

box_mean_plotR Documentation

Box plots of grouped data with optional mean value

Description

Creates a standard box plot of grouped data (line: median, box: 25 to 75 percentiles, whiskers: 1.5*IQR (interquartile range)).

Usage

box_mean_plot(
  d,
  x = NULL,
  y,
  color.group = NULL,
  x.axis = NULL,
  y.axis = NULL,
  legend.title = NULL,
  x.order = NULL,
  group.order = NULL,
  x.first = NULL,
  group.first = NULL,
  means = FALSE,
  boxwidth = 0.7,
  whisker.width = 1,
  mean.size = 1,
  points = TRUE,
  jitterwidth = 1,
  pointsize = 1,
  mean.type = "arithmetic"
)

Arguments

d

data.frame with data to be plotted.

x

Character. The name of the column to be used for the x axis (categorical data). If NULL, color.group needs to be supplied. Defaults to NULL.

y

Character. The name of the column to be used for the y axis (numeric data).

color.group

Character. The name of the column to be used for color grouping (categorical data). If NULL,x needs to be supplied. Defaults to NULL.

x.axis

Character. Sets the title of the x axis. If NULL, x axis title is given the value of x. Defaults to NULL.

y.axis

Character. Sets the title of the y axis. If NULL, y axis title is given the value of y. Defaults to NULL.

legend.title

Character. Sets the title of the legend. If NULL, legend title is given the value of color.group. Defaults to NULL.

x.order

Character vector of length equal to the number of x categories. Sets the order of categories in the x axis. If NULL, x categories are ordered alphabetically. Defaults to NULL.

group.order

Character vector of length equal to the number of color grouping categories. Sets the order of color groups. If NULL, color groups are ordered alphabetically. Defaults to NULL.

x.first

Character. Places a specific x axis category first. Ignored if x.order is supplied. Defaults to NULL.

group.first

Character. Places a specific color group category first. Ignored if group.order is supplied. Defaults to NULL.

means

Logical. Sets whether or not to plot group means. Defaults to FALSE.

boxwidth

Numeric. Sets the width of the bars. Defaults to 0.7.

whisker.width

Numeric. Sets the width of the error bar whiskers. Defaults to 1.

mean.size

Numeric. Sets the size of group mean points. Defaults to 1.

points

Logical. Sets whether or not to plot individual data points. Defaults to TRUE. Note that, even if set to FALSE, outliers will still be shown as individual data points, as is the norm in box plots.

jitterwidth

Numeric. The horizontal dispersion of individual data points. Defaults to 1.

pointsize

Numeric. Sets the size of individual data points. Defaults to 1.

mean.type

Character. Sets from arithmetic to geometric mean. Defaults to "arithmetic".

Details

To include the mean value for each group, set means argument to TRUE. To change between arithmetic or geometric mean, set the mean.type argument to "arithmetic" or "geometric".

The order of groups shown in the x axis and color groups defaults to alphabetical. To change it, supply x.order or group.order arguments. These should be character vectors with the desired order of each factor. Do not include categories that don't exist in the supplied data.frame. To bring just one category first, supply x.first or group.first arguments. If x.order is supplied, x.first will be ignored. The same holds for group.order and group.first.

Adjust other supplied arguments to customize the plot aesthetically.

Value

A plot based on ggplot2.


dimitriskokoretsis/datavis documentation built on Oct. 14, 2022, 3:35 p.m.