dat <- data.frame(group = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3),
y = c(3, 1, 4, 2, 5, 3, 2, 3, 6, 6, 3, NA))
# Example 1: Between-subject ANOVA
aov.b(y ~ group, data = dat)
# Example 2: Between-subject ANOVA
# print effect size measures
aov.b(y ~ group, data = dat, effsize = TRUE)
# Example 3: Between-subject ANOVA
# do not print hypotheses and descriptive statistics,
aov.b(y ~ group, data = dat, descript = FALSE, hypo = FALSE)
if (FALSE) {
# Example 4: Write results into a text file
aov.b(y ~ group, data = dat, write = "ANOVA.txt")}
# Example 5: Between-subject ANOVA
# plot results
aov.b(y ~ group, data = dat, plot = TRUE)
# Load ggplot2 package
library(ggplot2)
if (FALSE) {
# Example 6: Save plot, ggsave() from the ggplot2 package
ggsave("Between-Subject_ANOVA.png", dpi = 600, width = 4.5, height = 6)}
# Example 7: Between-subject ANOVA
# extract plot
p <- aov.b(y ~ group, data = dat, output = FALSE)$plot
p
# Extract data
plotdat <- aov.b(y ~ group, data = dat, output = FALSE)$data
# Draw plot in line with the default setting of aov.b()
ggplot(plotdat, aes(group, y)) +
geom_jitter(alpha = 0.1, width = 0.05, height = 0, size = 1.25) +
geom_point(stat = "summary", fun = "mean", size = 4) +
stat_summary(fun.data = "mean_cl_normal", geom = "errorbar", width = 0.20) +
scale_x_discrete(name = NULL) +
labs(subtitle = "Two-Sided Confidence Interval") +
theme_bw() + theme(plot.subtitle = element_text(hjust = 0.5))
Run the code above in your browser using DataLab