Использование упорядоченных факторов для группировки уровней в переменных.Я использовал оси Y, потому что уровни Region
являются кардинальными.
Best, Тайлер
library(tidyverse)
dat <- tribble(
~Region, ~Site, ~Value,
"South", "Site1", 0.1,
"South", "Site1", 0.3,
"South", "Site2", 0.24,
"South", "Site2", 0.03,
"South", "Site3", 0.06,
"South", "Site3", 0.14,
"South", "Site3", 0.02,
"Central", "Site4", 0.4,
"Central", "Site4", 0.32,
"Central", "Site4", 0.45,
"Central", "Site5", 0.22,
"Central", "Site5", 0.27,
"Central", "Site5", 0.13,
"Central", "Site6", 0.09,
"North", "Site7", 0.55,
"North", "Site7", 0.34,
"North", "Site8", 0.67,
"North", "Site9", 0.89,
"North", "Site9", 0.7,
"North", "Site9", 0.51)
dat <-
dat %>%
mutate(
Region = factor(x = Region, levels = c("South", "Central", "North"), ordered = T),
Site = factor(x = Site) %>% fct_rev())
ggplot(data = dat, mapping = aes(x = Region, y = Value, position = fct_rev(Site), fill = Site)) +
geom_boxplot() +
coord_flip()