bar_point_plot: Bar plots of grouped data with summary statistics

View source: R/bar_point_plot.R

bar_point_plotR Documentation

Bar plots of grouped data with summary statistics

Description

Creates a bar plot of grouped data means plus/minus standard deviations (or custom, manually calculated error measure).

Usage

bar_point_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,
  points = TRUE,
  barwidth = 0.7,
  jitterwidth = 1,
  pointsize = 1,
  whisker.width = 1,
  mean.type = "arithmetic",
  error.lower = NULL,
  error.upper = NULL
)

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.

points

Logical. Sets whether or not to plot individual data points. Defaults to TRUE.

barwidth

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

jitterwidth

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

pointsize

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

whisker.width

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

mean.type

Character, either "arithmetic" or "geometric". Sets which type of mean and standard deviation to plot. Defaults to "arithmetic".

error.lower

Character, name of a column in the d data.frame. Plot custom lower error bar, calculated by the user and included in the d data frame as a column. Defaults to NULL, which plots mean - SD.

error.upper

Character, name of a column in the d data.frame. Plot custom upper error bar, calculated by the user and included in the d data frame as a column. Defaults to NULL, which plots mean + SD.

Details

The calculations for mean and standard deviation are performed automatically. To show other error measure, calculate it manually and include it as two fields in the supplied data.frame (field names are supplied as error.lower and error.upper arguments). To change from arithmetic mean plus/minus standard deviation to the corresponding geometric parameters, set mean.type argument from "arithmetic" to "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 in first place, 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.