[R-sig-ME] new afex version: plot results from factorial designs with afex_plot()

Henrik Singmann @ingm@nn @ending from p@ychologie@uzh@ch
Wed Sep 26 15:58:39 CEST 2018


Dear list,

A few days ago I have released a new version of afex (0.22-1) to CRAN:
https://cran.r-project.org/package=afex

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.

For example:

library("afex")
library("ggplot2")

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) + 
(1|Block),
                         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:
https://singmann.github.io/afex_plot_introduction.html

Some more information on the types of error bars can be found at the 
help page:
https://www.rdocumentation.org/packages/afex/versions/0.22-1/topics/afex_plot

The full list of changes is on CRAN:
https://cran.rstudio.com/web/packages/afex/NEWS

I apologize for cross-posting,
Henrik


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
PostDoc
Universität Zürich, Schweiz
http://singmann.org



More information about the R-sig-mixed-models mailing list