rxnNorm | R Documentation |
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.
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(), ... )
formula |
A formula with both LHS and RHS. The formula should comply
with the usual |
data |
A data frame containing the response and categorical/factor data, and possibly group data. |
groups |
The (unquoted) name of a variable in |
cols |
A vector of colors to be used for factor 1; must be as along as the levels in factor 1. |
freckles |
Logical; if |
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 |
method |
One of |
table |
If NULL, the default, no action. If a vector of 3 numbers
|
legend |
If NULL, no action. If a vector of 3 numbers
|
theme |
Character; A suitable |
... |
Additional arguments to be passed downstream. |
The choices in method
are based upon functions in the
ChemoSpec
package which will need to be installed.
See ChemoSpec::.seXy
for the details.
A lattice
plot object is returned invisibly, and a plot is
created.
Bryan A. Hanson, DePauw University. hanson@depauw.edu
https://github.com/bryanhanson/HandyStuff
# ### 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.