knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(sf)

plot_the_hex_grid <- function(occ_df){
  hex_res <- 1  # hex_res 0 is too big to work, all others work
  hex <- obisindicators::make_hex_res(hex_res)
  # mapview::mapview(hex)  # you can view the hex grid with h3 IDs 

  # === Then assign cell numbers to the occurrence data:
  occ_df <- occ_df %>% 
    mutate(
      cell = h3::geo_to_h3(
        data.frame(decimalLatitude, decimalLongitude),
        res = hex_res))  # calc indicators
  idx <- calc_indicators(occ_df)
  # Add cell geometries to the indicators table:
  grid <- hex %>% 
    inner_join(
      idx,
      by = c("hexid" = "cell"))

  # Plot map
  gmap_indicator(grid, "es", label = "ES(50)")
}
plot_the_hex_grid(occ_1960s)
plot_the_hex_grid(occ_1970s)
plot_the_hex_grid(occ_1980s)
plot_the_hex_grid(occ_1990s)
plot_the_hex_grid(occ_2000s)
plot_the_hex_grid(occ_2010s)


marinebon/obisindicators documentation built on Dec. 14, 2022, 6:47 p.m.