Running examples in ‘afex-Ex.R’ failed
The error most likely occurred in:

> ### Name: afex_plot
> ### Title: m-way Plot with Error Bars and Raw Data
> ### Aliases: afex_plot afex_plot.afex_aov afex_plot.mixed afex_plot.merMod
> ###   afex_plot.default interaction_plot oneway_plot
> 
> ### ** Examples
> 
> # note: use library("ggplot") to avoid "ggplot2::" in the following
> 
> ##################################################################
> ##                2-factor Within-Subject Design                ##
> ##################################################################
> 
> data(md_12.1)
> aw <- aov_ez("id", "rt", md_12.1, within = c("angle", "noise"))
> 
> ##---------------------------------------------------------------
> ##                    Basic Interaction Plots                   -
> ##---------------------------------------------------------------
> 
> ## all examples require emmeans and ggplot2:
> if (requireNamespace("emmeans") && requireNamespace("ggplot2")) {
+ 
+ afex_plot(aw, x = "angle", trace = "noise") 
+ # or: afex_plot(aw, x = ~angle, trace = ~noise)
+ 
+ afex_plot(aw, x = "noise", trace = "angle")
+ 
+ ### For within-subject designs, using within-subject CIs is better:
+ afex_plot(aw, x = "angle", trace = "noise", error = "within") 
+ (p1 <- afex_plot(aw, x = "noise", trace = "angle", error = "within"))
+ 
+ ## use different themes for nicer graphs:
+ p1 + ggplot2::theme_bw()
+ }
Warning: Panel(s) show within-subjects factors, but not within-subjects error bars.
For within-subjects error bars use: error = "within"
Warning: Panel(s) show within-subjects factors, but not within-subjects error bars.
For within-subjects error bars use: error = "within"
> ## Not run: 
> ##D p1 + ggplot2::theme_light()
> ##D p1 + ggplot2::theme_minimal()
> ##D p1 + jtools::theme_apa()
> ##D p1 + ggpubr::theme_pubr()
> ##D 
> ##D ### set theme globally for R session:
> ##D ggplot2::theme_set(ggplot2::theme_bw())
> ##D 
> ##D ### There are several ways to deal with overlapping points in the background besides alpha
> ##D # Using the default data geom and ggplot2::position_jitterdodge
> ##D afex_plot(aw, x = "noise", trace = "angle", error = "within", dodge = 0.3,
> ##D           data_arg = list(
> ##D             position = 
> ##D               ggplot2::position_jitterdodge(
> ##D                 jitter.width = 0, 
> ##D                 jitter.height = 5, 
> ##D                 dodge.width = 0.3  ## needs to be same as dodge
> ##D                 )))
> ##D 
> ##D # Overlapping points are shown as larger points using geom_count
> ##D afex_plot(aw, x = "noise", trace = "angle", error = "within", dodge = 0.5,
> ##D                 data_geom = ggplot2::geom_count)
> ##D 
> ##D # Using ggbeeswarm::geom_quasirandom (overlapping points shown in violin shape)
> ##D afex_plot(aw, x = "noise", trace = "angle", error = "within", dodge = 0.5,
> ##D           data_geom = ggbeeswarm::geom_quasirandom,
> ##D           data_arg = list(
> ##D             dodge.width = 0.5,  ## needs to be same as dodge
> ##D             cex = 0.8))
> ##D 
> ##D 
> ##D # Using ggbeeswarm::geom_beeswarm (overlapping points are adjacent on y-axis)
> ##D afex_plot(aw, x = "noise", trace = "angle", error = "within", dodge = 0.5,
> ##D           data_geom = ggbeeswarm::geom_beeswarm,
> ##D           data_arg = list(
> ##D             dodge.width = 0.5,  ## needs to be same as dodge
> ##D             cex = 0.8))
> ##D 
> ##D # Do not display points, but use a violinplot: ggplot2::geom_violin
> ##D afex_plot(aw, x = "noise", trace = "angle", error = "within", 
> ##D           data_geom = ggplot2::geom_violin, 
> ##D           data_arg = list(width = 0.5))
> ##D 
> ##D # violinplots with color: ggplot2::geom_violin
> ##D afex_plot(aw, x = "noise", trace = "angle", error = "within", 
> ##D           mapping = c("linetype", "shape", "fill"),
> ##D           data_geom = ggplot2::geom_violin, 
> ##D           data_arg = list(width = 0.5))
> ##D 
> ##D # do not display points, but use a boxplot: ggplot2::geom_boxplot
> ##D afex_plot(aw, x = "noise", trace = "angle", error = "within", 
> ##D           data_geom = ggplot2::geom_boxplot, 
> ##D           data_arg = list(width = 0.3))
> ##D           
> ##D # combine points with boxplot: ggpol::geom_boxjitter
> ##D afex_plot(aw, x = "noise", trace = "angle", error = "within", 
> ##D           data_geom = ggpol::geom_boxjitter, 
> ##D           data_arg = list(width = 0.3))
> ##D ## hides error bars!
> ##D 
> ##D # nicer variant of ggpol::geom_boxjitter
> ##D afex_plot(aw, x = "noise", trace = "angle", error = "within", 
> ##D           mapping = c("shape", "fill"),
> ##D           data_geom = ggpol::geom_boxjitter, 
> ##D           data_arg = list(
> ##D             width = 0.3, 
> ##D             jitter.params = list(width = 0, height = 10),
> ##D             outlier.intersect = TRUE),
> ##D           point_arg = list(size = 2.5), 
> ##D           error_arg = list(linewidth = 1.5, width = 0))
> ##D 
> ##D # nicer variant of ggpol::geom_boxjitter without lines
> ##D afex_plot(aw, x = "noise", trace = "angle", error = "within", dodge = 0.7,
> ##D           mapping = c("shape", "fill"),
> ##D           data_geom = ggpol::geom_boxjitter, 
> ##D           data_arg = list(
> ##D             width = 0.5, 
> ##D             jitter.params = list(width = 0, height = 10),
> ##D             outlier.intersect = TRUE),
> ##D           point_arg = list(size = 2.5), 
> ##D           line_arg = list(linetype = 0),
> ##D           error_arg = list(linewidth = 1.5, width = 0))
> ##D 
> ##D ### we can also use multiple geoms for the background by passing a list of geoms
> ##D afex_plot(aw, x = "noise", trace = "angle", error = "within", 
> ##D           data_geom = list(
> ##D             ggplot2::geom_violin, 
> ##D             ggplot2::geom_point
> ##D           ))
> ##D 
> ##D ## with separate extra arguments:
> ##D 
> ##D afex_plot(aw, x = "noise", trace = "angle", error = "within", 
> ##D           dodge = 0.5,
> ##D           data_geom = list(
> ##D             ggplot2::geom_violin, 
> ##D             ggplot2::geom_point
> ##D           ), 
> ##D           data_arg = list(
> ##D             list(width = 0.4),
> ##D             list(position = 
> ##D                    ggplot2::position_jitterdodge(
> ##D                      jitter.width = 0, 
> ##D                      jitter.height = 5, 
> ##D                      dodge.width = 0.5  ## needs to be same as dodge
> ##D                    )))
> ##D           )
> ## End(Not run)
> 
> 
> ##---------------------------------------------------------------
> ##                        One-Way Plots                         -
> ##---------------------------------------------------------------
> 
> ## Not run: 
> ##D afex_plot(aw, x = "angle", error = "within") ## default
> ##D 
> ##D ## with color we need larger points
> ##D afex_plot(aw, x = "angle", mapping = "color", error = "within", 
> ##D           point_arg = list(size = 2.5), 
> ##D           error_arg = list(linewidth = 1.5, width = 0.05)) 
> ##D 
> ##D afex_plot(aw, x = "angle", error = "within", data_geom = ggpol::geom_boxjitter)
> ##D 
> ##D ## nicer
> ##D afex_plot(aw, x = "angle", error = "within", data_geom = ggpol::geom_boxjitter, 
> ##D           mapping = "fill", data_alpha = 0.7, 
> ##D           data_arg = list(
> ##D             width = 0.6, 
> ##D             jitter.params = list(width = 0.07, height = 10),
> ##D             outlier.intersect = TRUE
> ##D           ),
> ##D           point_arg = list(size = 2.5), 
> ##D           error_arg = list(linewidth = 1.5, width = 0.05))
> ##D 
> ##D ## we can use multiple geoms with separate argument lists:
> ##D afex_plot(aw, x = "angle", error = "within", 
> ##D           data_geom = 
> ##D             list(ggplot2::geom_violin, ggplot2::geom_boxplot), 
> ##D           data_arg = 
> ##D             list(list(width = 0.7), list(width = 0.1)))
> ##D 
> ##D ## we can add a line connecting the means using geom_point(aes(group = 1)):
> ##D afex_plot(aw, x = "angle", error = "within") +
> ##D   ggplot2::geom_line(ggplot2::aes(group = 1))
> ##D 
> ##D ## we can also add lines connecting the individual data-point in the bg.
> ##D # to deal with overlapping points, we use geom_count and make means larger
> ##D afex_plot(aw, x = "angle", error = "within", 
> ##D           data_geom = list(ggplot2::geom_count, ggplot2::geom_line), 
> ##D           data_arg = list(list(), list(mapping = ggplot2::aes(group = id))), 
> ##D           point_arg = list(size = 2.5), 
> ##D           error_arg = list(width = 0, linewidth = 1.5)) +
> ##D   ggplot2::geom_line(ggplot2::aes(group = 1), linewidth = 1.5)
> ##D 
> ##D ## One-way plots also supports panels:
> ##D afex_plot(aw, x = "angle", panel = "noise", error = "within")
> ##D 
> ##D ## And panels with lines:
> ##D afex_plot(aw, x = "angle", panel = "noise", error = "within") +
> ##D   ggplot2::geom_line(ggplot2::aes(group = 1))
> ##D 
> ##D 
> ##D ## For more complicated plots it is easier to attach ggplot2:
> ##D library("ggplot2")
> ##D 
> ##D ## We can hide geoms by plotting them in transparent color and add them
> ##D ## afterward to use a mapping not directly supported. 
> ##D ## For example, the next plot adds a line to a one-way plot with panels, but 
> ##D ## with all geoms in the foreground having a color conditional on the panel.
> ##D 
> ##D afex_plot(aw, x = "angle", panel = "noise", error = "within", 
> ##D           point_arg = list(color = "transparent"), 
> ##D           error_arg = list(color = "transparent")) +
> ##D   geom_point(aes(color = panel)) +
> ##D   geom_linerange(aes(color = panel, ymin = lower, ymax = upper)) + 
> ##D   geom_line(aes(group = 1, color = panel)) +
> ##D   guides(color = guide_legend(title = "NOISE"))
> ##D ## Note that we need to use guides explicitly, otherwise the legend title would 
> ##D ## be "panel". legend_title does not work in this case.
> ##D 
> ##D ##---------------------------------------------------------------
> ##D ##                      Other Basic Options                     -
> ##D ##---------------------------------------------------------------
> ##D 
> ##D ## relabel factor levels via factor_levels (with message)
> ##D afex_plot(aw, x = "noise", trace = "angle", 
> ##D           factor_levels = list(angle = c("0°", "4°", "8°"),
> ##D                                noise = c("Absent", "Present")))
> ##D 
> ##D ## factor_levels allows named vectors which enable reordering the factor levels 
> ##D ### and renaming subsets of levels:
> ##D afex_plot(aw, x = "noise", trace = "angle", 
> ##D           factor_levels = list(
> ##D             angle = c(X8 = "8°", X4 = "4°", X0 = "0°"),
> ##D             noise = c(present = "Present")
> ##D           )
> ##D )
> ##D 
> ##D 
> ##D ## Change title of legend
> ##D afex_plot(aw, x = "noise", trace = "angle", 
> ##D           legend_title = "Noise Condition")
> ##D 
> ##D ## for plots with few factor levels, smaller dodge might be better:
> ##D afex_plot(aw, x = "angle", trace = "noise", dodge = 0.25) 
> ##D 
> ##D #################################################################
> ##D ##                    4-factor Mixed Design                    ##
> ##D #################################################################
> ##D 
> ##D data(obk.long, package = "afex")
> ##D a1 <- aov_car(value ~ treatment * gender + Error(id/(phase*hour)), 
> ##D               data = obk.long, observed = "gender")
> ##D 
> ##D ## too difficult to see anything
> ##D afex_plot(a1, ~phase*hour, ~treatment) +
> ##D   ggplot2::theme_light()
> ##D 
> ##D ## better
> ##D afex_plot(a1, ~hour, ~treatment, ~phase) +
> ##D   ggplot2::theme_light()
> ##D 
> ##D ## even better
> ##D afex_plot(a1, ~hour, ~treatment, ~phase, 
> ##D           dodge = 0.65, 
> ##D           data_arg = list(
> ##D             position = 
> ##D               ggplot2::position_jitterdodge(
> ##D                 jitter.width = 0, 
> ##D                 jitter.height = 0.2, 
> ##D                 dodge.width = 0.65  ## needs to be same as dodge
> ##D                 ),
> ##D             color = "darkgrey")) +
> ##D   ggplot2::theme_classic()
> ##D 
> ##D # with color instead of linetype to separate trace factor
> ##D afex_plot(a1, ~hour, ~treatment, ~phase, 
> ##D           mapping = c("shape", "color"),
> ##D           dodge = 0.65, 
> ##D           data_arg = list(
> ##D             position = 
> ##D               ggplot2::position_jitterdodge(
> ##D                 jitter.width = 0, 
> ##D                 jitter.height = 0.2, 
> ##D                 dodge.width = 0.65  ## needs to be same as dodge
> ##D                 ))) +
> ##D   ggplot2::theme_light()
> ##D 
> ##D # only color to separate trace factor
> ##D afex_plot(a1, ~hour, ~treatment, ~phase, 
> ##D           mapping = c("color"),
> ##D           dodge = 0.65, 
> ##D           data_color = NULL,  ## needs to be set to NULL to avoid error
> ##D           data_arg = list(
> ##D             position = 
> ##D               ggplot2::position_jitterdodge(
> ##D                 jitter.width = 0, 
> ##D                 jitter.height = 0.2, 
> ##D                 dodge.width = 0.65  ## needs to be same as dodge
> ##D                 ))) +
> ##D   ggplot2::theme_classic()
> ##D 
> ##D 
> ##D ## plot involving all 4 factors:
> ##D afex_plot(a1, ~hour, ~treatment, ~gender+phase, 
> ##D           dodge = 0.65, 
> ##D           data_arg = list(
> ##D             position = 
> ##D               ggplot2::position_jitterdodge(
> ##D                 jitter.width = 0, 
> ##D                 jitter.height = 0.2, 
> ##D                 dodge.width = 0.65  ## needs to be same as dodge
> ##D                 ),
> ##D             color = "darkgrey")) +
> ##D   ggplot2::theme_bw()
> ##D 
> ##D 
> ##D ##---------------------------------------------------------------
> ##D ##              Different Standard Errors Available             -
> ##D ##---------------------------------------------------------------
> ##D 
> ##D ## purely within-design
> ##D cbind(
> ##D   afex_plot(a1, ~phase, ~hour, 
> ##D             error = "model", return = "data")$means[,c("phase", "hour", "y", "SE")],
> ##D   multivariate = afex_plot(a1, ~phase, ~hour,
> ##D                            error = "model", return = "data")$means$error,
> ##D   mean = afex_plot(a1, ~phase, ~hour, 
> ##D                     error = "mean", return = "data")$means$error,
> ##D   within = afex_plot(a1, ~phase, ~hour, 
> ##D                      error = "within", return = "data")$means$error,
> ##D   between = afex_plot(a1, ~phase, ~hour, 
> ##D                       error = "between", return = "data")$means$error)
> ##D ## mixed design
> ##D cbind(
> ##D   afex_plot(a1, ~phase, ~treatment, 
> ##D             error = "model", return = "data")$means[,c("phase", "treatment", "y", "SE")],
> ##D   multivariate = afex_plot(a1, ~phase, ~treatment,
> ##D                            error = "model", return = "data")$means$error,
> ##D   mean = afex_plot(a1, ~phase, ~treatment, 
> ##D                     error = "mean", return = "data")$means$error,
> ##D   within = afex_plot(a1, ~phase, ~treatment, 
> ##D                      error = "within", return = "data")$means$error,
> ##D   between = afex_plot(a1, ~phase, ~treatment, 
> ##D                       error = "between", return = "data")$means$error)
> ## End(Not run)
> 
> ##################################################################
> ##                         Mixed Models                         ##
> ##################################################################
> if (requireNamespace("MEMSS") && 
+     requireNamespace("emmeans") && 
+     requireNamespace("ggplot2")) {
+ 
+ data("Machines", package = "MEMSS") 
+ m1 <- mixed(score ~ Machine + (Machine|Worker), data=Machines)
+ pairs(emmeans::emmeans(m1, "Machine"))
+ # contrast   estimate       SE df t.ratio p.value
+ # A - B     -7.966667 2.420850  5  -3.291  0.0481
+ # A - C    -13.916667 1.540100  5  -9.036  0.0007
+ # B - C     -5.950000 2.446475  5  -2.432  0.1253
+ 
+ ## Default (i.e., model-based) error bars suggest no difference between Machines.
+ ## This contrasts with pairwise comparisons above.
+ afex_plot(m1, "Machine")
+ 
+ ## Impression from within-subject error bars is more in line with pattern of differences.
+ afex_plot(m1, "Machine", error = "within")
+ }
Loading required namespace: MEMSS
Contrasts set to contr.sum for the following variables: Machine, Worker
Error in tcrossprod(sc * Li) : "tcrossprod" is not a BUILTIN function
Calls: pairs ... VarCorr.merMod -> structure -> mkVarCorr -> lapply -> FUN
Execution halted