lineChart: Plot data with a line chart

Description Usage Arguments Value See Also Examples

View source: R/LineChart-functions.R

Description

This function is the primary interface to the LineChart package.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
lineChart(
  formula,
  data,
  settings = NULL,
  centralTendencyType = "mean",
  errBarType = "SE",
  title = "",
  xlab = NULL,
  ylab = NULL,
  xlim = NULL,
  ylim = NULL,
  plotXAxis = TRUE,
  plotYAxis = TRUE,
  legendPosition = "CHOOSE_BEST",
  legendTitle = "GROUP_NAME",
  lwd.axes = par()$lwd,
  add = FALSE,
  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.

title

The title to place at the top of the plot.

xlab

The label to place on the x-axis. If NULL (default), the name of the source of data for the x-variable will be used, if available.

ylab

The label to place on the y-axis. If NULL (default), the name of the source of data for the y-variable will be used if available.

xlim

The plotting range of the x-axis.

ylim

The plotting range of the y-axis.

plotXAxis

Should the x-axis be plotted?

plotYAxis

Should the y-axis be plotted?

legendPosition

The position at which the legend should be placed. If NULL, no legend is plotted. If "CHOOSE_BEST", the best legend position is selected. Otherise, it is passed through to legend() directly.

legendTitle

The title to be used in the legend box. If "GROUP_NAME" (default), the name of the source of data for the grouping variable will be used. If no legend title is desired, use NULL.

lwd.axes

The line width of the axes and box around the plotting area.

add

If FALSE, a new plot will be started and the data plotted in it. If TRUE, the data will be plotted in the current plotting device, if any.

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.

...

Additional parameters, currently passed on to the legend creating functions.

Value

The plotting data frame that was used is returned invisibly. It contains all of the information used to create the plot.

See Also

createPlottingDf, lineChartDf, buildGroupSettings, extractGroupSettings, applySettingsToPlottingDf, legendFromPlottingDf, legendFromSettings

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#Basic use case: Plotting data frame with default appearance.
data(ChickWeight)
lineChart(weight ~ Time * Diet, ChickWeight)

#You can modify the appearance of groups by providing group settings:
settings = buildGroupSettings(group=1:4, symbol=21:24, lty=1:4, 
  fillColor=gray(seq(0, 1, length.out = 4)))
lineChart(weight ~ Time * Diet, ChickWeight, settings=settings)

#Let's ignore group 3
settings[ settings$group == 3, "include" ] = FALSE 
lineChart(weight ~ Time * Diet, ChickWeight, settings=settings)

#If for whatever reason you have data in two different data frames that you 
#want in the same plot, use add=TRUE to add to the existing plot.
cw12 = ChickWeight[ ChickWeight$Diet %in% 1:2, ]
cw34 = ChickWeight[ ChickWeight$Diet %in% 3:4, ]

#Distinguish between the groups by fill color.
settings$fillColor = c("white", "white", "black", "black") 
settings$include = TRUE #Include all groups

lineChart(weight ~ Time * Diet, cw12, legendPosition="topleft", 
  settings=settings, ylim=c(40,300))
lineChart(weight ~ Time * Diet, cw34, legendPosition="bottomright", 
  settings=settings, add=TRUE)
#The legend doesn't update, but another legend gets added.

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