yarrr (version 0.1.5)

pirateplot: pirateplot

Description

The pirateplot function creates an RDI (Raw data, Descriptive and Inferential statistic) plot showing the relationship between 1 to 3 categorical independent variables and 1 continuous dependent variable.

Usage

pirateplot(formula = NULL, data = NULL, plot = TRUE,
  avg.line.fun = mean, pal = "basel", mix.col = "white", mix.p = 0,
  back.col = NULL, point.cex = NULL, point.pch = NULL, point.lwd = 1,
  jitter.val = 0.03, theme = 1, bean.b.o = NULL, bean.f.o = NULL,
  point.o = NULL, bar.f.o = NULL, bar.b.o = NULL, inf.f.o = NULL,
  inf.b.o = NULL, avg.line.o = NULL, gl.col = NULL, point.col = NULL,
  point.bg = NULL, bar.f.col = NULL, bean.b.col = NULL,
  bean.f.col = NULL, inf.f.col = NULL, inf.b.col = NULL,
  avg.line.col = NULL, bar.b.col = NULL, quant.col = NULL,
  avg.line.lwd = 4, bean.lwd = 1, bean.lty = 1, inf.lwd = NULL,
  bar.lwd = 1, at = NULL, bw = "nrd0", adjust = 1, add = FALSE,
  sortx = "alphabetical", decreasing = FALSE, cex.lab = 1, cex.axis = 1,
  cex.names = 1, quant = NULL, quant.length = NULL, quant.lwd = NULL,
  quant.boxplot = FALSE, bty = "o", cap.beans = TRUE, family = NULL,
  inf.method = "hdi", inf.within = NULL, inf.p = NULL, hdi.iter = 1000,
  inf.disp = NULL, cut.min = NULL, cut.max = NULL, width.min = 0.3,
  width.max = NA, ylim = NULL, xlim = NULL, xlab = NULL, ylab = NULL,
  main = NULL, yaxt = NULL, xaxt = NULL, gl = NULL, gl.lwd = NULL,
  gl.lty = NULL, bar.b.lwd = NULL, line.fun = NULL, line.o = NULL,
  inf.o = NULL, bean.o = NULL, inf.col = NULL, theme.o = NULL,
  bar.o = NULL, inf = NULL, hdi.o = NULL, inf.type = NULL,
  inf.band = NULL)

Arguments

formula
formula. A formula in the form y ~ x1 + x2 + x3 indicating the vertical response variable (y) and up to three independent variables
data
Either a dataframe containing the variables specified in formula, a list of numeric vectors, or a numeric dataframe / matrix.
plot
logical. If TRUE (the default), thent the pirateplot is produced. If FALSE, the data summaries created in the plot are returned as a list.
avg.line.fun
function. A function that determines how average lines and bar heights are determined (default is mean).
pal
string. The color palette of the plot. Can be a single color, a vector of colors, or the name of a palette in the piratepal() function (e.g.; "basel", "google", "southpark"). To see all the palettes, run piratepal(palette = "all", action = "show")
mix.col, mix.p
Optional color mixing arguments to be passed to piratepal. See ?piratepal for examples.
back.col
string. Color of the plotting background.
point.cex, point.pch, point.lwd
numeric. The size, pch type, and line width of raw data points.
jitter.val
numeric. Amount of jitter added to points horizontally. Defaults to 0.05.
theme
integer. An integer in the set 0, 1, 2 specifying a theme (that is, new default values for opacities and colors). theme = 0 turns off all opacities which can then be individually specified individually.
bar.f.o, point.o, inf.f.o, inf.b.o, avg.line.o, bean.b.o, bean.f.o, bar.b.o
numeric. A number between 0 and 1 indicating how opaque to make the bars, points, inference band, average line, and beans respectively. These values override whatever is in the specified theme
point.col, bar.f.col, bean.b.col, bean.f.col, inf.f.col, inf.b.col, avg.line.col, bar.b.col, quant.col, point.bg
string. Vectors of colors specifying the colors of the plotting elements. This will override values in the palette. f stands for filling, b stands for border.
bean.lwd, bean.lty, inf.lwd, avg.line.lwd, bar.lwd
numeric. Vectors of numbers customizing the look of beans and lines.
at
integer. Locations of the beans. Especially helpful when adding beans to an existing plot with add = TRUE
bw, adjust
Arguments passed to density calculations for beans (see ?density)
add
logical. Should the pirateplot elements be added to an existing plotting space?
sortx
string. How to sort the x values. Can be "sequential" (as they are found in the original dataframe), "alphabetical", or a string in the set ("mean", "median", "min", "max") indicating a function
decreasing
logical. If sortx is a named function, should values be sorted in decreasing order?
cex.lab, cex.axis, cex.names
Size of the labels, axes, and bean names.
quant
numeric. Adds horizontal lines representing custom quantiles.
quant.length, quant.lwd
numeric. Specifies line lengths/widths of quant.
quant.boxplot
logical. Should standard values be included?
bty, xlim, ylim, xlab, ylab, main, yaxt, xaxt
General plotting arguments
cap.beans
logical. Should maximum and minimum values of the bean densities be capped at the limits found in the data? Default is FALSE.
family
a font family (Not currently in use)
inf.method
string. A string indicating what types of inference bands to calculate. "ci" means frequentist confidence intervals, "hdi" means Bayesian Highest Density Intervals (HDI), "iqr" means interquartile range, "sd" means standard deviation, "se" means standard error, "withinci" means frequentist confidence intervals in a within design (Morey, 2008).
inf.within
string. The variable which serves as an ID variable in a within design.
inf.p
numeric. A number adjusting how inference ranges are calculated. for "ci" and "hdi", a number between 0 and 1 indicating the level of confidence (default is .95). For "sd" and "se", the number of standard deviations / standard errors added to or subtracted from the mean (default is 1).
hdi.iter
integer. Number of iterations to run when calculating the HDI. Larger values lead to better estimates, but can be more time consuming.
inf.disp
string. How should inference ranges be displayed? "line" creates a classic vertical line, "rect" creates a rectangle, "bean" forms the inference around the bean.
cut.min, cut.max
numeric. Optional minimum and maximum values of the beans.
width.min, width.max
numeric. The minimum/maximum width of the beans.
gl
numeric. Locations of the horizontal grid lines
gl.lwd, gl.lty, gl.col
Customization for grid lines. Can be entered as vectors for alternating gridline types
bar.b.lwd, line.fun, inf.o, bean.o, inf.col, theme.o, inf, inf.type, inf.band, bar.o, line.o, hdi.o
depricated arguments

Examples

Run this code


# Default pirateplot of weight by Time
pirateplot(formula = weight ~ Time,
          data = ChickWeight)

# Same but in grayscale
pirateplot(formula = weight ~ Time,
          data = ChickWeight,
          pal = "gray")


# Now using theme 2
pirateplot(formula = weight ~ Time,
          data = ChickWeight,
          main = "Chicken weight by time",
          theme = 2) # theme 2

# theme 3
pirateplot(formula = weight ~ Time,
          data = ChickWeight,
          main = "Chicken weight by time",
          theme = 3) # theme 3

# theme 4
pirateplot(formula = weight ~ Time,
          data = ChickWeight,
          main = "Chicken weight by time",
          theme = 4) # theme 4

# Start with theme 2, but then customise!
pirateplot(formula = weight ~ Time,
          data = ChickWeight,
          theme = 2, # theme 2
          pal = "xmen", # xmen palette
          main = "Chicken weights by Time",
          point.o = .4, # Add points
          point.col = "black",
          point.bg = "white",
          point.pch = 21,
          bean.f.o = .2, # Turn down bean filling
          inf.f.o = .8, # Turn up inf filling
          gl.col = "gray", # gridlines
          gl.lwd = c(.5, 0)) # turn off minor grid lines

# 2 IVs
pirateplot(formula = len ~ dose + supp,
          data = ToothGrowth,
          main = "Guinea pig tooth length by supplement",
          point.pch = 16,  # Point specifications...
          point.col = "black",
          point.o = .7,
          inf.f.o = .9, # inference band opacity
          gl.col = "gray")


# Build everything from scratch with theme 0
#  And use 3 IVs
pirateplot(formula = height ~ headband + eyepatch + sex,
          data = pirates,
          pal = gray(.1), # Dark gray palette
          theme = 0, # Start from scratch
          inf.f.o = .7, # Band opacity
          inf.f.col = piratepal("basel"), # Add color to bands
          point.o = .1, # Point opacity
          avg.line.o = .8, # Average line opacity
          gl.col = gray(.6), # Gridline specifications
          gl.lty = 1,
          gl.lwd = c(.5, 0))

  # See the vignette for more details
 vignette("pirateplot", package = "yarrr")


Run the code above in your browser using DataLab