Open dicook opened 13 hours ago
If the user has a factor variable with appropriate levels, they can convert it to numeric prior to passing the argument to the plotting function.
aus_temp |>
mutate(month_fct = factor(case_when(month == 1 ~ "Jan",
month == 2 ~ "Feb",
month == 3 ~ "Mar",
month == 4 ~ "Apr",
month == 5 ~ "May",
month == 6 ~ "Jun",
month == 7 ~ "Jul",
month == 8 ~ "Aug",
month == 9 ~ "Sep",
month == 10 ~ "Oct",
month == 11 ~ "Nov",
month == 12 ~ "Dec"),
levels = c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))) |>
ggplot(aes(x_major = long, y_major = lat,
x_minor = as.numeric(month_fct), ymin_minor = tmin, ymax_minor = tmax)) +
geom_glyph_ribbon()
I could modify the function to handle factor variables directly, but this would require me to hardcode the group argument and force them to be identical. For some reason, factors generate multiple groupings, which disrupts the plotting.
What are your thoughts on this?
It might be worthwhile to handle factor versions of the x_major variable. Currently if month is coded as J, F, .... the code errors