geom_pirate: Pirate plots

Description Usage Arguments Examples

View source: R/geom_pirate.R

Description

A pirate plot (https://cran.r-project.org/web/packages/yarrr/vignettes/pirateplot.html) is a way of displaying data where a continuous dependent variable is a function of a categorical independent variable, in a more informative way than the traditional barplot. geom_pirate plots the raw data as points (using geom_jitter), along with layers showing descriptive and inferential statistics – bars indicating means (using geom_col), horizontal line indicating means (using geom_crossbar), boxes indicating 95% confidence intervals assuming a normal sampling distribution (using geom_tile), and violins indicating the density (using geom_violin).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
geom_pirate(
  mapping = NULL,
  data = NULL,
  ...,
  points = TRUE,
  bars = TRUE,
  lines = TRUE,
  cis = TRUE,
  violins = TRUE,
  points_params = list(shape = 1, size = 1),
  bars_params = list(alpha = 0.3, width = 0.9),
  lines_params = list(size = 0.5, width = 0.9),
  cis_params = list(fill = "white", size = 0.5, alpha = 0.5, width = 0.8),
  violins_params = list(fill = "white", size = 0.5, alpha = 0, width = 0.7),
  jitter_width = 0.2,
  na.rm = FALSE,
  show.legend = FALSE,
  inherit.aes = TRUE
)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)).

...

Other arguments passed on to layer(). These are often aesthetics, used to set an aesthetic to a fixed value, like colour = "red" or size = 3. They may also be parameters to the paired geom/stat.

points

logical indicating whether to show points

bars

logical indicating whether to show mean bars

lines

logical indicating whether to show mean lines

cis

logical indicating whether to show 95% confidence intervals boxes

violins

logical indicating whether to show violins

points_params

list of parameters to pass to points layer

bars_params

list of parameters to pass to bars layer

lines_params

list of parameters to pass to lines layer

cis_params

list of parameters to pass to CIs layer

violins_params

list of parameters to pass to violins layer

jitter_width

amount of horizontal jitter added to the locations of the points (defaults to 20% of the resolution of the data)

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

show.legend

logical indicating whether this layer be included in the legends (defaults to FALSE)

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders().

Examples

1
2
ggplot(mpg, aes(x = class, y = cty)) +
  geom_pirate(aes(colour = class))

mikabr/ggpirate documentation built on Aug. 8, 2020, 1:47 p.m.