[R-sig-ME] new afex version: plot results from factorial designs with afex_plot()
@ingm@nn @ending from p@ychologie@uzh@ch
Wed Sep 26 15:58:39 CEST 2018
A few days ago I have released a new version of afex (0.22-1) to CRAN:
The main news is a new generic for plotting results from factorial
designs. afex_plot() combines estimated marginal means and associated
error bars with a depiction of the raw data in the background.
Currently, afex_plots() supports ANOVAs and mixed models fitted with
afex as well as models fitted with lme4 (support for more models will
come in the next version). It also allows different types of error bars,
including within-subjects confidence intervals.
afex_plots() is built on ggplot2 and designed in a modular manner,
making it easy to customize the plot to ones personal preferences. The
perhaps most important customizations are:
(a) Changing the mapping (in ggplot2 parlance) of the trace/x factor(s).
That is, they way in which different levels of the factor(s) are
visually represented. The default is mapping = c("shape", "linetype")
for the trace factor(s) but, any combination of c("shape", "color",
"linetype", "fill") can make sense.
(b) Changing the geom for the data plotted in the background. The
default uses geom_point, but many others such as geom_boxplot or
geom_violin are possible.
Oats <- nlme::Oats
## afex_plot does currently not support implicit nesting: (1|Block/Variety)
## Instead, we need to create the factor explicitly
Oats$VarBlock <- Oats$Variety:Oats$Block
Oats.lmer <- lmer(yield ~ Variety * factor(nitro) + (1|VarBlock) +
data = Oats)
## basic plots:
afex_plot(Oats.lmer, x = "nitro", trace = "Variety")
afex_plot(Oats.lmer, x = "nitro", panel = "Variety")
# some customization:
afex_plot(Oats.lmer, x = "nitro", trace = "Variety",
mapping = c("fill", "shape"), dodge = 0.8,
data_geom = geom_violin,
data_arg = list(width = 0.7))
An overview of the functionality is provided in the vignette:
Some more information on the types of error bars can be found at the
The full list of changes is on CRAN:
I apologize for cross-posting,
PS: There is an error in the vignette on CRAN and the help page. The
correct argument name for new factor levels is "factor_levels" and not
"new_levels". The vignette linked to above is already corrected.
Dr. Henrik Singmann
Universität Zürich, Schweiz
More information about the R-sig-mixed-models