maliny12 / sugarglider

Sugarglider creates glyph maps to visualise spatio-temporal data with customisable ribbon and segment geometries.
https://maliny12.github.io/sugarglider/
Other
2 stars 0 forks source link

if month is not numeric #11

Open dicook opened 13 hours ago

dicook commented 13 hours ago

It might be worthwhile to handle factor versions of the x_major variable. Currently if month is coded as J, F, .... the code errors

maliny12 commented 6 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.

Screenshot 2024-09-29 at 10 49 08 PM

What are your thoughts on this?