rxnNorm: Create a Reaction Norm or Interaction Plot

View source: R/rxnNorm.R

rxnNormR Documentation

Create a Reaction Norm or Interaction Plot

Description

Draws a reaction norm or interaction plot as typically used in ecology to demonstrate treatment x genotype interactions. The x axis can be categorical or numeric. There are options to plot the raw data points in addition to a choice of several summary methods. The central values may be connected or the entire data set fitted to a line. A summary table is optional, and gives either counts at each level, an ANOVA table or fit data.

Usage

rxnNorm(
  formula = NULL,
  data = NULL,
  groups = NULL,
  cols = NULL,
  freckles = FALSE,
  type = "connect",
  method = c("sem", "sem95", "iqr", "mad"),
  table = NULL,
  legend = c(0.5, 0.5, 1),
  theme = screenTheme(),
  ...
)

Arguments

formula

A formula with both LHS and RHS. The formula should comply with the usual lattice conventions, for instance y ~ x_factor.

data

A data frame containing the response and categorical/factor data, and possibly group data.

groups

The (unquoted) name of a variable in data to serve as the grouping variable.

cols

A vector of colors to be used for factor 1; must be as along as the levels in factor 1.

freckles

Logical; if TRUE, the actual data points are plotted as small points, hence the name, jittered slightly in the horizontal direction only.

type

Either "connect", "fitLine" , "anova" or "anovaNoLine". In the first case, a line is drawn which connects the chosen measure of central tendency (e.g. mean) for each value of fac1. This would generally be used when the x value are categorical. In the second case, a linear fit is performed and the line is drawn; used for continuous x values. In the third case, a connecting line is drawn along with an ANOVA summary table. Finally, in the fourth case no line is drawn and the ANOVA summary table is provided.

method

One of c("sem", "sem95", "iqr", "mad"). Each produces a dot at the measure of central tendency and error bars corresponding to the requested method ("box" currently does not work quite right). Full details are in ChemoSpec::.seXy.

table

If NULL, the default, no action. If a vector of 3 numbers c(x, y, cex), a summary table is placed at the given coordinates with font size cex. The table contains either a summary of counts (if type = "connect"), a report of the linear fit (if type = "fitLine") or an ANOVA table (if type = "anova". The coordinates are in device units so 0.5, 0.5 puts the table dead center in the plotting region.

legend

If NULL, no action. If a vector of 3 numbers c(x, y, cex), a legend is placed at the given coordinates with font size cex. The coordinates are in device units so 0.5, 0.5 puts the legend dead center in the plotting region.

theme

Character; A suitable lattice theme. There are two built-in themes which you can use "as is" or modify to your heart's content. If none is given, screenTheme will be used. The other option provided is posterTheme.

...

Additional arguments to be passed downstream.

Details

The choices in method are based upon functions in the ChemoSpec package which will need to be installed. See ChemoSpec::.seXy for the details.

Value

A lattice plot object is returned invisibly, and a plot is created.

Author(s)

Bryan A. Hanson, DePauw University. hanson@depauw.edu

References

https://github.com/bryanhanson/HandyStuff

Examples

#
### set up demo data
#
require("ChemoSpec")
require("lattice")
require("gridExtra")

set.seed(79)
res = c(rnorm(10, 5, 1.5), rnorm(10, 8, 2),
rnorm(10, 14, 2.0), rnorm(10, 10, 1.5),
rnorm(10, 15, 2), rnorm(10, 12,2.5))
fac1 <- c(rep("L", 20), rep("M", 20), rep("H", 20))
fac1 <- factor(fac1, levels = c("L", "M", "H"))
fac2 <- sample(c("A", "B"), 60, replace = TRUE)
fac2 <- as.factor(fac2)
num <- c(rep(5, 20), rep(10, 20), rep(12, 20))
td <- data.frame(resp = res, fac1 = fac1, fac2 = fac2, num = num)
#
### Numeric x with lm and summary table:
#
p <- rxnNorm(formula = resp~num, groups = fac2, data = td,
method = "iqr", freckles = TRUE, type = "fitLine",
cols = c("red", "blue"), table = c(0.5, 0.3, 0.75),
legend = c(0.175, 0.84, 1.0),
main = "rxnNorm - linear model w/fit table")
print(p)
#
### Categorical x, connected and summary table:
#
p <- rxnNorm(formula = resp~fac1, groups = fac2, data = td,
method = "iqr", freckles = TRUE, type = "connect",
cols = c("red", "blue"), table = c(0.5, 0.3, 0.75),
legend = c(0.175, 0.84, 1.0),
main = "rxnNorm - Categorical x w/summary table")
print(p)
#
### Categorical x, connected with ANOVA table:
#
p <- rxnNorm(formula = resp~fac1, groups = fac2, data = td,
method = "iqr", freckles = TRUE, type = "anova",
cols = c("red", "blue"), table = c(0.57, 0.2, 0.75),
legend = c(0.175, 0.84, 1.0),
main = "rxnNorm - Categorical x w/ANOVA table")
print(p)



bryanhanson/HandyStuff documentation built on July 22, 2022, 6:18 a.m.