compareCats | R Documentation |
This function allows one to generate a nice plot comparing a response from
samples falling into one or two categories with corresponding levels.
lattice
is used to create plots, with options to include the original
data and to use various measures of central tendency and spread. A count of
the number of samples in each level is included. Gives a visual impression
of the data to go along with hypothesis tests.
compareCats( formula = NULL, data = NULL, cols = NULL, freckles = FALSE, method = c("sem", "sem95", "iqr", "mad", "box", "points"), 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. A maximum two categories with any number of levels can be plotted at one time. |
cols |
A vector of colors to be used for factor 1; must be as along as the levels in factor 1. |
freckles |
Logical; if |
method |
One of |
theme |
Character; A suitable |
... |
Other parameters to be passed downstream. |
The supplied data frame is stripped down to just the response and factor
columns, then NAs
are removed; the counts reflect this.
A lattice
object. These can be modified by the usual methods
associated with these packages.
Bryan A. Hanson, DePauw University. hanson@depauw.edu
https://github.com/bryanhanson/HandyStuff
# ### Set up test data # require("ChemoSpec") require("lattice") require("latticeExtra") require("plyr") mydf <- data.frame( resp = rnorm(40), cat1 = sample(LETTERS[1:3], 40, replace = TRUE), cat2 = sample(letters[1:2], 40, replace = TRUE), stringsAsFactors = TRUE) # ### One factor: # p <- compareCats(formula = resp~cat1, data = mydf, method = "sem", freckles = TRUE, poster = FALSE, cols = c("red", "orange", "blue")) print(p) # ### Two factors: # p <- compareCats(formula = resp~cat1 | cat2, data = mydf, method = "sem", freckles = TRUE, cols = c("red", "orange", "blue")) print(p) # ### Interchange the roles of the factors # p <- compareCats(formula = resp~cat2 | cat1, data = mydf, method = "sem", freckles = TRUE, cols = c("red", "blue")) print(p)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.