plot_lines: Display means conditionnally on some other values

View source: R/visualization.R

plot_linesR Documentation

Display means conditionnally on some other values

Description

The typical use of this function is to represents trends of average along some categorical variable.

Usage

plot_lines(
  fml,
  data,
  time,
  moderator,
  mod.select,
  mod.NA = TRUE,
  smoothing_window = 0,
  fun,
  col = "set1",
  lty = 1,
  pch = c(19, 17, 15, 8, 5, 4, 3, 1),
  legend_options = list(),
  pt.cex = 2,
  lwd = 2,
  dict = NULL,
  mod.title = TRUE,
  ...
)

Arguments

fml

A formula of the type variable ~ time | moderator. Note that the moderator is optional. Can also be a vector representing the elements of the variable If a formula is provided, then you must add the argument ‘data’. You can use multiple variables. If so, you cannot use a moderator at the same time.

data

Data frame containing the variables of the formula. Used only if the argument ‘fml’ is a formula.

time

Only if argument ‘fml’ is a vector. It should be the vector of ‘time’ identifiers to average over.

moderator

Only if argument ‘fml’ is a vector. It should be a vector of conditional values to average over. This is an optional parameter.

mod.select

Which moderators to select. By default the top 5 moderators in terms of frequency (or in terms of the value of fun in case of identical frequencies) are displayed. If provided, it must be a vector of moderator values whose length cannot be greater than 10. Alternatively, you can put an integer between 1 and 10.

mod.NA

Logical, default is FALSE. If TRUE, and if the moderator contains NA values, all NA values from the moderator will be treated as a regular case: allows to display the distribution for missing values.

smoothing_window

Default is 0. The number of time periods to average over. Note that if it is provided the new value for each period is the average of the current period and the smoothing_window time periods before and after.

fun

Function to apply when aggregating the values on the time variable. Default is mean.

col

The colors. Either a vector or a keyword (“Set1” or “paired”). By default those are the “Set1” colors colorBrewer. This argument is used only if there is a moderator.

lty

The line types, in the case there are more than one moderator. By default it is equal to 1 (ie no difference between moderators).

pch

The form types of the points, in the case there are more than one moderator. By default it is equal to \8codec(19, 17, 15, 8, 5, 4, 3, 1).

legend_options

A list containing additional parameters for the function legend – only concerns the moderator. Note that you can set the additionnal arguments trunc and trunc.method which relates to the number of characters to show and the truncation method. By default the algorithm truncates automatically when needed.

pt.cex

Default to 2. The cex of the points.

lwd

Default to 2. The width of the lines.

dict

A dictionnary to rename the variables names in the axes and legend. Should be a named vector. By default it s the value of getFplot_dict(), which you can set with the function setFplot_dict.

mod.title

Character scalar. The title of the legend in case there is a moderator. You can set it to TRUE (the default) to display the moderator name. To display no title, set it to NULL or FALSE.

...

Other arguments to be passed to the function plot.

Value

This function returns invisibly the output data.table containing the processed data used for plotting.

Author(s)

Laurent Berge

Examples


data(airquality)

plot_lines(Ozone ~ Day, airquality)

plot_lines(Ozone ~ Day | Month, airquality)

plot_lines(Ozone ~ Month | cut(Day, 8), airquality)



fplot documentation built on Aug. 24, 2023, 5:09 p.m.