createPlottingDf: Creates a plottable data frame.

Description Usage Arguments Details Value Examples

View source: R/LineChart-functions.R

Description

This function creates a data frame that can be used for plotting from a user-supplied data frame. The user data will be aggregated based on the formula. The resulting plotting data frame can be used with lineChartDf.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
createPlottingDf(
  formula,
  data,
  settings = NULL,
  centralTendencyType = "mean",
  errBarType = "SE",
  xOrder = NULL,
  replicate = NULL,
  repFun = mean
)

Arguments

formula

The formula should be of the form y ~ x or y ~ x * g1 * g2 * ... * gK, where the gN are any number of grouping variables and y, x, and gi are the names of columns in data. If grouping variables are used, x must come before them.

data

A data frame containing the data to be used in creation of the plotting data frame.

settings

Plotting settings for the different groups in the data, such as the symbol to use.

centralTendencyType

Character or function. The type of central tendency measure to use. Can be "mean" or "median". If a function, should be a function of one vector argument that returns a scalar.

errBarType

The type of error bar to use. Can be "SE" for standard error, "SD" for standard deviation, "CI95" for a 95% confidence interval, or "Cred95" for 95% credible interval. If NULL, no error bars are created. If a function is supplied, the function should take one vector argument, which is the data used to plot a single data point. It should return either 1) a length-2 vector or 2) a list with two elements. If returning 1), the values in the vector should be distances from the central tendency measure that the error bars should be drawn (i.e. they should be more-or-less centered on 0). If returning 2), the list should contain eb, which is either a) error bar distances OR b) error bar endpoints, and includesCenter, which indicates whether eb is distances or endpoints. If eb is distances, then it does not include the center, so includesCenter should be FALSE. If eb is endpoints, then it does include the center, so includesCenter should be TRUE.

xOrder

The order in which to plot the x variable. A character vector containing all of the levels of the x variable in the order in which they should be plotted. If the x variable is numeric or can be coerced to numeric, this argument does nothing.

replicate

The name of a column in data providing indices for replicates (e.g. a participant number). The data will be aggregated for each replicate with repFun before being plotted. Do not include the replicate column in formula.

repFun

A function that is used to aggregate values for each replicate. Defaults to mean.

Details

Note that if no grouping variables are supplied by the formula, a group column will still be made in the resulting data frame and the group name will be the number 0.

Value

A data.frame which can be plotted with lineChartDf. See the documentation for lineChartDf for examples.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
data(ChickWeight)

#Example of a user-defined central tendency function:
trimmedMedian = function(x) {
  #trim highest and lowest values
  x = sort(x)[ 2:(length(x) - 1) ]
  median(x)
}

#Example of a user-defined error bar function:
quartiles = function(x) {
  qs = as.numeric(quantile(x, c(0.25, 0.75)))
  list(eb=qs, includesCenter=TRUE)
}

plotDf = createPlottingDf(weight ~ Time * Diet, ChickWeight, 
  centralTendencyType=trimmedMedian, errBarType=quartiles)
lineChartDf(plotDf)

hardmanko/LineChart-package documentation built on Aug. 26, 2020, 10:39 a.m.