After a Tukey test using rstatix
, I would like to add another column to the data frame with the Tukey groups.
library(tidyverse)
library(rstatix)
ggplot(data = iris,
aes(x = Species,
y = Petal.Length)) +
geom_boxplot()
Tukey <- iris %>%
tukey_hsd(Petal.Length ~ Species) %>%
add_significance() %>%
# ????? <------- Help here
I'm expecting something like this:
> Tukey
# A tibble: 3 x 9
term group1 group2 null.value estimate conf.low conf.high p.adj p.adj.signif group
* <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr>
1 Species setosa versicolor 0 2.80 2.59 3.00 3e-15 **** A
2 Species setosa virginica 0 4.09 3.89 4.29 3e-15 **** B
3 Species versicolor virginica 0 1.29 1.09 1.50 3e-15 **** C
Extra: If it is possible, please help me to put the letters of the groups over each box of the boxplot.