p1 <- ggplot(mpg, aes(factor(cyl), hwy)) +
geom_boxplot(width = 0.33)
## labeleld bars
p1 +
stat_multcomp()
p1 +
stat_multcomp(adj.method.tag = 0)
# test against a control, with first level being the control
# change order of factor levels in data to set the control group
p1 +
stat_multcomp(contrasts = "Dunnet")
# arbitrary pairwise contrasts, in arbitrary order
p1 +
stat_multcomp(contrasts = rbind(c(0, 0, -1, 1),
c(0, -1, 1, 0),
c(-1, 1, 0, 0)))
# different methods to adjust the contrasts
p1 +
stat_multcomp(p.adjust.method = "bonferroni")
p1 +
stat_multcomp(p.adjust.method = "holm")
p1 +
stat_multcomp(p.adjust.method = "fdr")
# no correction, useful only for comparison
p1 +
stat_multcomp(p.adjust.method = "none")
# sometimes we need to expand the plotting area
p1 +
stat_multcomp(geom = "text_pairwise") +
scale_y_continuous(expand = expansion(mult = c(0.05, 0.10)))
# position of contrasts' bars (based on scale limits)
p1 +
stat_multcomp(label.y = "bottom")
p1 +
stat_multcomp(label.y = 11)
# use different labels: difference and P-value from hypothesis tests
p1 +
stat_multcomp(use_label("Delta", "P"),
size = 2.75)
# control smallest P-value displayed and number of digits
p1 +
stat_multcomp(p.digits = 4)
# label only significant differences
# but test and correct for all pairwise contrasts!
p1 +
stat_multcomp(mc.cutoff.p.value = 0.01)
## letters as labels for test results
p1 +
stat_multcomp(label.type = "letters")
# use capital letters
p1 +
stat_multcomp(label.type = "LETTERS")
# location
p1 +
stat_multcomp(label.type = "letters",
label.y = "top")
p1 +
stat_multcomp(label.type = "letters",
label.y = 0)
# stricter critical p-value than default used for test
p1 +
stat_multcomp(label.type = "letters",
mc.critical.p.value = 0.01)
# Inspecting the returned data using geom_debug()
# This provides a quick way of finding out the names of the variables that
# are available for mapping to aesthetics with after_stat().
gginnards.installed <- requireNamespace("gginnards", quietly = TRUE)
if (gginnards.installed)
library(gginnards)
if (gginnards.installed)
p1 +
stat_multcomp(label.type = "bars",
geom = "debug")
if (gginnards.installed)
p1 +
stat_multcomp(label.type = "letters",
geom = "debug")
if (gginnards.installed)
p1 +
stat_multcomp(label.type = "bars",
output.type = "numeric",
geom = "debug")
Run the code above in your browser using DataLab