Standardise season as a factor with ordered seasons. If an "annual" category is present it includes at the end of the other seasons. Season names are converted to sentence case
order_season_levels(x)a factor with ordered levels for season
library(ggplot2)
library(tibble)
seasons <- tribble(
~ season, ~n,
"autum", 1,
"summer", 2,
"winter", 3,
"spring", 1,
"annual", 2)
# unordered ugly plot
qplot(season, n, fill = season, data = seasons, geom = "col")
#> Warning: `qplot()` was deprecated in ggplot2 3.4.0.
ordered_seasons <- dplyr::mutate(seasons,
season = order_season_levels(season))
#> Warning: There was 1 warning in `dplyr::mutate()`.
#> ℹ In argument: `season = order_season_levels(season)`.
#> Caused by warning in `order_season_levels()`:
#> ! Autum not recognised as valid season name(s)
# nice ordered plot
qplot(season, n, fill = season, data = ordered_seasons, geom = "col")