From the official data by Santé Publique France, we spatially smooth the decease (produced by SPF at the département scale) and normalize by a similarly smoothed population grid. For that we use the {btb} package.
# Carto décès COVID 19 France# avec lissagemap_date <-"2020-04-06"# config ------------------------------------------------------------------library(tidyverse)library(httr)library(fs)library(sf)library(readxl)library(janitor)library(glue)library(tmap)library(grid)library(classInt)# + btb, raster, fasterize, plyr# sources -----------------------------------------------------------------# https://www.data.gouv.fr/fr/datasets/donnees-hospitalieres-relatives-a-lepidemie-de-covid-19/fichier_covid <-"donnees/covid.csv"url_donnees_covid <-"https://www.data.gouv.fr/fr/datasets/r/63352e38-d353-4b54-bfd1-f1b3ee1cabd7"# https://www.insee.fr/fr/statistiques/2012713#tableau-TCRD_004_tab1_departementsfichier_pop <-"donnees/pop.xlsx"url_donnees_pop <-"https://www.insee.fr/fr/statistiques/fichier/2012713/TCRD_004.xlsx"# Adminexpress : à télécharger manuellement# https://geoservices.ign.fr/documentation/diffusion/telechargement-donnees-libres.html#admin-expressaex <-path_expand("~/data/adminexpress/adminexpress_cog_simpl_000_2022.gpkg")rayon <-1e5# distance de lissage (m)pixel <-10000# résolution grille (m)force_download <-TRUE# retélécharger même si le fichier existe et a été téléchargé aujourd'hui ?#' Kernel weighted smoothing with arbitrary bounding area#'#' @param df sf object (points)#' @param field weight field in the df#' @param bandwidth kernel bandwidth (map units)#' @param resolution output grid resolution (map units)#' @param zone sf study zone (polygon)#' @param out_crs EPSG (should be an equal-area projection)#'#' @return a raster object#' @import btb, raster, fasterize, dplyr, plyr, sflissage <-function(df, field, bandwidth, resolution, zone, out_crs =3035) {if (st_crs(zone)$epsg !=st_crs(out_crs)$epsg) {message("reprojecting data...") zone <-st_transform(zone, out_crs) }if (st_crs(df)$epsg !=st_crs(out_crs)$epsg) {message("reprojecting study zone...") df <-st_transform(df, out_crs) } zone_bbox <-st_bbox(zone)# grid generationmessage("generating reference grid...") zone_xy <- zone %>% dplyr::select(all_of(attr(zone, "sf_column"))) %>%st_make_grid(cellsize = resolution,offset =c( plyr::round_any(zone_bbox[1] - bandwidth, resolution, f = floor), plyr::round_any(zone_bbox[2] - bandwidth, resolution, f = floor) ),what ="centers" ) %>%st_sf() %>%st_join(zone, join = st_intersects, left =FALSE) %>%st_coordinates() %>%as_tibble() %>% dplyr::select(x = X, y = Y)# kernelmessage("computing kernel...") kernel <- df %>%cbind(., st_coordinates(.)) %>%st_set_geometry(NULL) %>% dplyr::select(x = X, y = Y, field) %>% btb::btb_smooth(sEPSG = out_crs,iCellSize = resolution,iBandwidth = bandwidth,vQuantiles =NULL,dfCentroids = zone_xy )# rasterizationmessage("\nrasterizing...") raster::raster(xmn = plyr::round_any(zone_bbox[1] - bandwidth, resolution, f = floor),ymn = plyr::round_any(zone_bbox[2] - bandwidth, resolution, f = floor),xmx = plyr::round_any(zone_bbox[3] + bandwidth, resolution, f = ceiling),ymx = plyr::round_any(zone_bbox[4] + bandwidth, resolution, f = ceiling),resolution = resolution,crs =st_crs(out_crs)$epsg ) %>% fasterize::fasterize(kernel, ., field = field)}# téléchargement--------------------------------------------------------------dir_create("donnees")dir_create("results")if (!file_exists(fichier_covid) |file_info(fichier_covid)$modification_time <Sys.Date() | force_download) {GET(url_donnees_covid,progress(),write_disk(fichier_covid, overwrite =TRUE))}