eliocamp / metR

Tools for Easier Analysis of Meteorological Fields
https://eliocamp.github.io/metR/
143 stars 22 forks source link

There is a hole in Australia #193

Open paocorrales opened 2 months ago

paocorrales commented 2 months ago

Adding breaks = seq(-1, 20, 1) fixes the hole.

library(data.table)
library(ggplot2)
library(metR)

obs <- fread("https://raw.githubusercontent.com/paocorrales/t-fall/main/acorn_sat_v2.5.0_daily_tmax/t_fall.csv")

aus <- rnaturalearth::ne_states(country = "Australia", returnclass = "sf")

obs |> 
  ggplot(aes(longitude, latitude)) +
  geom_contour_fill(aes(z = mean_front), kriging = 150, clip = aus) +
  geom_point(aes(fill = mean_front), shape = 21) +
  scale_color_viridis_c(guide = guide_colorbar(barwidth = 0.5,
                                               barheigh = 15), direction = -1) +
  scale_fill_viridis_c(guide = guide_colorbar(barwidth = 0.5,
                                              barheigh = 15), direction = -1) +
  geom_sf(data = aus, inherit.aes = FALSE, fill = NA) +
  coord_sf(ylim = c(-45, -8)) +
  labs(x = NULL, y = NULL, title = "Mean annual occurrence of falls in daily maximum \ntemperature of at least 10 K", 
       fill = NULL) +
  theme_minimal()
eliocamp commented 2 months ago

The problem is that the kriging algorithm interpolated values outside the observed range (~0, in this case), but the automatic breaks are computed using the data range.

It's not trivial because the breaks are computed in the setup_params step which is run before any step that modifies data in ggplot2. So setup_params would need to krige the data just to throw away the result. I guess I could krige the data at that stage and memoise the result and retrieve it in the compute_group/setup_data step.