From f16a80752ebdd35aaf846dae383bf73faad714bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Grelot?= <frederic.grelot@irstea.fr>
Date: Sun, 23 Jan 2022 00:41:07 +0100
Subject: [PATCH] =?UTF-8?q?geau=20Version=201.0.7.0=200=20errors=20?=
 =?UTF-8?q?=E2=9C=94=20|=200=20warnings=20=E2=9C=94=20|=200=20notes=20?=
 =?UTF-8?q?=E2=9C=94?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- map_so_ii
	- ajout du thème onrn, gestion des detail n_catnat, freq_sin, cost, cost_hab, cost_mean, ratio, balance, ppri_year
	- réorganisation du code pour theme dans l'ordre alphabétique
- so_ii_onrn dataset
	- inclusion & aide
- so_ii_clc
	- correction de l'aide
- so_ii_limit
	- correction de l'aide

Refs #7
---
 geau/DESCRIPTION           |   2 +-
 geau/R/data.r              | 193 +++++++++++--------
 geau/R/map_so_ii.r         | 378 ++++++++++++++++++++++++-------------
 geau/data-raw/so_ii_onrn.R |  28 +++
 geau/data/so_ii_onrn.rda   | Bin 0 -> 2936 bytes
 geau/man/map_so_ii.Rd      |   4 +-
 geau/man/so_ii_clc.Rd      |   8 +-
 geau/man/so_ii_limit.Rd    |  10 -
 geau/man/so_ii_onrn.Rd     |  50 +++++
 9 files changed, 453 insertions(+), 220 deletions(-)
 create mode 100644 geau/data-raw/so_ii_onrn.R
 create mode 100644 geau/data/so_ii_onrn.rda
 create mode 100644 geau/man/so_ii_onrn.Rd

diff --git a/geau/DESCRIPTION b/geau/DESCRIPTION
index 168cad4..6d9acb0 100644
--- a/geau/DESCRIPTION
+++ b/geau/DESCRIPTION
@@ -1,6 +1,6 @@
 Package: geau
 Title: Utilities very useful to share within geau-inondation team
-Version: 1.0.6.1
+Version: 1.0.7.0
 Authors@R:
     c(
         person(given = "Frédéric",
diff --git a/geau/R/data.r b/geau/R/data.r
index 7528b6f..11d1c53 100644
--- a/geau/R/data.r
+++ b/geau/R/data.r
@@ -1,10 +1,55 @@
-#' Local collectivities included in so-ii
+#' Color and label for CLC
 #'
-#' A dataset containing the INSEE code of all local collectivities
-#' (communes) included in so-ii
+#' A dataset proposing default colors and labels for plotting CLC
 #'
-#' @format a vector of 78 INSEE code
-"so_ii_scope"
+#' @format data.frame 5 rows, 3 variables
+"clc_color"
+
+#' Catchment areas of interest within the so-ii perimeter
+#'
+#' A dataset containing the official catchments areas of interest from the BD 
+#' TOPAGE within the so-ii perimeter. For degre = 3, the data are basically
+#' what is found in BD TOPAGE. For degres 1 and 2, the data result from
+#' sf::st_union of data of degre 3 to give a more synthetic representation.
+#'
+#' @format sf data.frame 15 rows, 4 variables
+#' \describe{
+#'   \item{id}{id, from BD TOPAGE (corresponding to CdOh) or NA when catchment
+#'      is constructed by so-ii team.}
+#'   \item{name}{character, name of the catchment area in BD TOPAGE, or given
+#'      name for catchments constructed by so-ii team.}
+#'   \item{degre}{factor, importance of the catchment used to plot the
+#'      catchment areas with different levels of detail ("1", "2", "3").}
+#' }
+#'
+#' @source \url{http://bdtopage.eaufrance.fr/page/objectifs}
+"so_ii_catchment"
+
+#' Number of Cat Nat events for the municipalities of so-ii
+#'
+#' A dataset containing the number of Cat Nat events (linked to flood) by year
+#' and so-ii municipality according to the GASPAR database.
+#'
+#' @format array with 3 dimensions
+#' \describe{
+#'   \item{first}{commune as in so_ii_scope}
+#'   \item{second}{year of Cat Nat events}
+#'   \item{third}{type of hazard}
+#' }
+#'
+#' @source \url{https://www.georisques.gouv.fr/donnees/bases-de-donnees/base-gaspar} # nolint
+"so_ii_catnat"
+
+#' CLC information for so-ii
+#'
+#' A dataset containing the Corine Land Cover information on so-ii.
+#'
+#' @format sf data.frame 1337 rows, 2 variables
+#' \describe{
+#'   \item{clc_2018}{character, classification from CLC 2018}
+#'   \item{color}{character, default color to be used to plot so_ii_clc}
+#' }
+"so_ii_clc"
 
 #' Spatial definition of collectivities included in so-ii
 #'
@@ -37,6 +82,25 @@
 #' @source \url{https://www.data.gouv.fr/fr/datasets/admin-express/}
 "so_ii_collectivity"
 
+#' Hydrographic network within the so-ii perimeter
+#'
+#' A dataset containing the official hydrographic network from the BD TOPAGE
+#' within the so-ii perimeter.
+#'
+#' @format sf data.frame 125 rows, 4 variables
+#' \describe{
+#'   \item{id}{id, from BD TOPAGE (corresponding to CdOh)}
+#'   \item{name}{character, name of the hydrographic elements in the BD TOPAGE}
+#'   \item{degre}{factor, level of importance of the hydrographic element
+#'      used to plot the hydrographic network with different levels of
+#'      detail ("1", "2", "3").}
+#'   \item{type}{factor, type of hydrographic element ("canal", "river",
+#'      "waterbody")}
+#' }
+#'
+#' @source \url{http://bdtopage.eaufrance.fr/page/objectifs}
+"so_ii_hydro"
+
 #' Spatial perimeter of so-ii
 #'
 #' A dataset containing the perimeter of so-ii.
@@ -47,16 +111,53 @@
 #' @format sfc_POLYGON of length 1
 "so_ii_limit"
 
-#' CLC information for so-ii
+#' Local collectivities included in so-ii
 #'
-#' A dataset containing the Corine Land Cover information on so-ii.
+#' A dataset containing the INSEE code of all local collectivities
+#' (communes) included in so-ii
 #'
-#' @format sf data.frame 1337 rows, 2 variables
+#' @format a vector of 78 INSEE code
+"so_ii_scope"
+
+#' ONRN information for so-ii
+#'
+#' A dataset containing part of the information available at the ONRN for so-ii
+#' communities. The information chosen is exclusively related to floods. It is
+#' mainly related to impacts and therefore to the claims in from the Cat-Nat
+#' system. These data on claims are taken from the CCR, the others from the
+#' gaspar database.
+#'
+#' @format data.frame 78 rows, 23 variables
 #' \describe{
-#'   \item{clc_2018}{character, classification from CLC 2018}
-#'   \item{color}{character, default color to be used to plot so_ii_clc}
+#'   \item{n_catnat}{Number of Cat Nat events}
+#'   \item{freq_sin}{Number of claims divided by number of contracts
+#'      for 1995 to 2018. freq_sin is calculated as the mean of freq_sin_min
+#'      and freq_sin_max (range for each category).}
+#'   \item{cost}{Cumulative cost of claims for 1995 to 2018. Cost is calculated
+#'      as the mean of cost_min and cost_max (range for each category).}
+#'   \item{cost_mean}{Mean cost of claims (cost divided by claims) for 1995 to
+#'      2018. cost_mean is calculated as the mean of cost_mean_min and
+#'      cost_mean_max (range for each category).}
+#'   \item{cost_hab}{Cost divided by the population for 1995 to 2018. cost_hab
+#'      is calculated as the mean of cost_hab_min and cost_hab_max (range for
+#'      each category).}
+#'   \item{ratio}{Cost divided by premium for 1995 to 2018. ratio is calculated
+#'      as the mean of cost_hab_min and cost_hab_max (range for each
+#'      category).}
+#'   \item{balance}{Cost minus premium for 1995 to 2018. This is an estimation
+#'      made by so-ii team by considering a mean premium for each habitant
+#'      of 24.92829 euro per habitant (total premium in 2018 divided by
+#'      total population)}
+#'   \item{ppri_year}{Year given for the last PPRI.}
+#'   \item{ppri_state}{State of the last PPRI.}
+#'   \item{ppri_state_sub}{Some details on the state of the last PPRI.}
+#'   \item{ppri_state_age}{State of the last PPRI for age information.}
+#'   \item{ppri_age_min}{Lower boundary for the age of the PPRI.}
+#'   \item{ppri_age_min}{Upper boundary for the age of the PPRI..}
 #' }
-"so_ii_limit"
+#'
+#' @source \url{https://www.georisques.gouv.fr/articles-risques/acceder-aux-indicateurs-sinistralite}
+"so_ii_onrn"
 
 #' Population for so-ii
 #'
@@ -69,72 +170,4 @@
 #' }
 #'
 #' @source \url{https://www.insee.fr/fr/statistiques/2522602}
-"so_ii_population"
-
-#' Number of Cat Nat events for the municipalities of so-ii
-#'
-#' A dataset containing the number of Cat Nat events (linked to flood) by year
-#' and so-ii municipality according to the GASPAR database.
-#'
-#' @format array with 3 dimensions
-#' \describe{
-#'   \item{first}{commune as in so_ii_scope}
-#'   \item{second}{year of Cat Nat events}
-#'   \item{third}{type of hazard}
-#' }
-#'
-#' @source \url{https://www.georisques.gouv.fr/donnees/bases-de-donnees/base-gaspar} # nolint
-"so_ii_catnat"
-
-#' CLC information for so-ii
-#'
-#' A dataset containing the 2018 version of CLC information for so-ii
-#'
-#' @format sf object
-"so_ii_clc"
-
-#' Color and label for CLC
-#'
-#' A dataset proposing default colors and labels for plotting CLC
-#'
-#' @format data.frame 5 rows, 3 variables
-"clc_color"
-
-#' Hydrographic network within the so-ii perimeter
-#'
-#' A dataset containing the official hydrographic network from the BD TOPAGE
-#' within the so-ii perimeter.
-#'
-#' @format sf data.frame 125 rows, 4 variables
-#' \describe{
-#'   \item{id}{id, from BD TOPAGE (corresponding to CdOh)}
-#'   \item{name}{character, name of the hydrographic elements in the BD TOPAGE}
-#'   \item{degre}{factor, level of importance of the hydrographic element
-#'      used to plot the hydrographic network with different levels of
-#'      detail ("1", "2", "3").}
-#'   \item{type}{factor, type of hydrographic element ("canal", "river",
-#'      "waterbody")}
-#' }
-#'
-#' @source \url{http://bdtopage.eaufrance.fr/page/objectifs}
-"so_ii_hydro"
-
-#' Catchment areas of interest within the so-ii perimeter
-#'
-#' A dataset containing the official catchments areas of interest from the BD 
-#' TOPAGE within the so-ii perimeter. For degre = 3, the data are basically
-#' what is found in BD TOPAGE. For degres 1 and 2, the data result from
-#' sf::st_union of data of degre 3 to give a more synthetic representation.
-#'
-#' @format sf data.frame 15 rows, 4 variables
-#' \describe{
-#'   \item{id}{id, from BD TOPAGE (corresponding to CdOh) or NA when catchment
-#'      is constructed by so-ii team.}
-#'   \item{name}{character, name of the catchment area in BD TOPAGE, or given
-#'      name for catchments constructed by so-ii team.}
-#'   \item{degre}{factor, importance of the catchment used to plot the
-#'      catchment areas with different levels of detail ("1", "2", "3").}
-#' }
-#'
-#' @source \url{http://bdtopage.eaufrance.fr/page/objectifs}
-"so_ii_catchment"
\ No newline at end of file
+"so_ii_population"
\ No newline at end of file
diff --git a/geau/R/map_so_ii.r b/geau/R/map_so_ii.r
index d165283..5eb7b23 100644
--- a/geau/R/map_so_ii.r
+++ b/geau/R/map_so_ii.r
@@ -16,6 +16,8 @@
 #'      levels of detail or "canal", "river", "waterbody" for types of
 #'      hydrographic elements. If missing, "none" will be chosen, and
 #'      everything is plotted.}
+#'   \item{\strong{onrn}: detail must be chosen in "n_catnat", "freq_sin",
+#'      "cost", "cost_hab", "cost_mean", "ratio", "balance", "ppri_year".}
 #' }
 #' }
 #' \subsection{year specification}{
@@ -55,7 +57,7 @@
 map_so_ii = function(
     dataset,
     dataset_legend = NULL,
-    theme = c("none", "collectivity", "catchment", "catnat", "clc", "hydro", "population"),
+    theme = c("none", "collectivity", "catchment", "catnat", "clc", "hydro", "onrn", "population"),
     bar = TRUE,
     path = NULL,
     legend_theme = FALSE,
@@ -79,6 +81,102 @@ map_so_ii = function(
     graphics::par(mai = c(.65, .60, .50, .15))
     plot(geau::so_ii_limit, axes = TRUE)
 
+    if ("catchment" %in% theme) {
+        if (missing(detail)) {
+            detail = "1"
+        }
+        detail = match.arg(
+            as.character(detail), 
+            choices = levels(geau::so_ii_catchment[["degre"]])
+        )
+        selection  = geau::so_ii_catchment[["degre"]] == detail
+        geometry = geau::so_ii_catchment[["geometry"]][selection]
+        catchment = as.factor(geau::so_ii_catchment[["catchment_name"]][selection])
+        color_legend = grDevices::hcl.colors(nlevels(catchment), "Pastel 1", alpha = .3)
+        color = color_legend[catchment]
+        border = "grey80"
+        lwd = 2
+        theme_legend = list(
+            title = sprintf("Bassin versant"),
+            legend = levels(catchment),
+            x = "topright",
+            cex = .8,
+            bg = "white",
+            inset = 0.01,
+            fill = color_legend,
+            border = border
+        )
+        if (detail == "3") rm(theme_legend)
+
+        plot(geometry, border = border, col = color, lwd = lwd, add = TRUE)
+    }
+
+    if ("catnat" %in% theme) {
+        if (missing(detail)) {
+            detail = dimnames(geau::so_ii_catnat)[["hazard"]]
+        }
+        detail = match.arg(
+            detail, 
+            dimnames(geau::so_ii_catnat)[["hazard"]],
+            several.ok = TRUE
+        )
+        border = NA
+        color = NA
+        if (!missing(year)) {
+            year = match.arg(
+                as.character(year),
+                dimnames(geau::so_ii_catnat)[["period"]]
+            )
+            border = "grey80"
+            catnat = apply(
+                geau::so_ii_catnat[, year, detail, drop = FALSE],
+                1:2,
+                sum
+            )
+            color = ifelse(
+                catnat > 0,
+                scales::alpha("grey80", .5),
+                NA
+            )
+            theme_legend = list(
+                title = sprintf("Cat-Nat %s", year),
+                legend = c("Sans d\u00e9claration", "Avec d\u00e9claration"),
+                x = "topright",
+                cex = .8,
+                bg = "white",
+                inset = 0.01,
+                fill = unique(color),
+                border = border
+            )
+        }
+
+        plot(
+            geau::so_ii_collectivity[["geometry"]],
+            border = border,
+            col = color,
+            add = TRUE
+        )
+    }
+
+    if ("clc" %in% theme) {
+        plot(
+            geau::so_ii_clc[["geometry"]],
+            border = NA,
+            col = geau::so_ii_clc[["color"]],
+            add = TRUE
+        )
+
+        theme_legend = list(
+            title = "CLC (2018)",
+            legend = geau::clc_color[["label_fr"]],
+            x = "topright",
+            cex = .8,
+            bg = "white",
+            inset = 0.01,
+            fill = geau::clc_color[["color"]]
+        )
+    }
+
     if ("collectivity" %in% theme) {
         if (missing(detail)) {
             detail = "none"
@@ -136,23 +234,167 @@ map_so_ii = function(
         }
     }
 
-    if ("clc" %in% theme) {
+    if ("hydro" %in% theme) {
+        if (missing(detail)) {
+            detail = "none"
+        }
+        detail = match.arg(
+            as.character(detail),
+            choices = c(
+                "none",
+                levels(geau::so_ii_hydro[["degre"]]),
+                levels(geau::so_ii_hydro[["type"]])
+            )
+        )
+        color = scales::alpha("blue", .3)
+        bg = scales::alpha("blue", .3)
+        border = NA
+        selection = seq(nrow(geau::so_ii_hydro))
+        theme_legend = list(
+            title = sprintf("R\u00e9seau hydrographique"),
+            legend = "\u00e9l\u00e9ment du r\u00e9seau",
+            x = "topright",
+            cex = .8,
+            bg = "white",
+            inset = 0.01,
+            col = color,
+            lwd = 1
+        )
+        if (detail %in% levels(geau::so_ii_hydro[["type"]])) {
+            selection  = as.character(geau::so_ii_hydro[["type"]]) == detail
+            theme_legend[["legend"]] = detail
+        }
+        if (detail %in% levels(geau::so_ii_hydro[["degre"]])) {
+            selection  = as.character(geau::so_ii_hydro[["degre"]]) <= detail
+        }
+        geometry = geau::so_ii_hydro[["geometry"]][selection]
+        lwd = 4 - as.numeric(geau::so_ii_hydro[["degre"]][selection])
+
+        plot(geometry, col = color, lwd = lwd, border = border, add = TRUE)
+    }
+
+    if ("onrn" %in% theme) {
+        if (missing(detail)) {
+            detail = "cost"
+        }
+        detail = match.arg(
+            as.character(detail),
+            sort(colnames(geau::so_ii_onrn)[1:8])
+        )
+
+        onrn_palette = switch(
+            EXPR = detail,
+            "n_catnat"  = scales::colour_ramp(c("white", "red"), alpha = .5),
+            "freq_sin"  = scales::colour_ramp(c("white", "red"), alpha = .5),
+            "cost"      = scales::colour_ramp(c("white", "red"), alpha = .5),
+            "cost_hab"  = scales::colour_ramp(c("white", "red"), alpha = .5),
+            "cost_mean" = scales::colour_ramp(c("white", "red"), alpha = .5),
+            "ratio"     = scales::colour_ramp(c("green", "white", "red"), alpha = .5),
+            "balance"   = scales::colour_ramp(c("red", "white", "green"), alpha = .5),
+            "ppri_year" = scales::colour_ramp(c("grey80", "grey50"), alpha = .5),
+            NULL
+        )
+        onrn_trans = switch(
+            EXPR = detail,
+            "n_catnat"  = scales::identity_trans(),
+            "freq_sin"  = scales::identity_trans(),
+            "cost"      = scales::sqrt_trans(),
+            "cost_hab"  = scales::sqrt_trans(),
+            "cost_mean" = scales::sqrt_trans(),
+            "ratio"     = scales::sqrt_trans(),
+            "balance"   = scales::modulus_trans(.5),
+            "ppri_year" = scales::identity_trans(),
+            NULL
+        )
+        onrn_range = switch(
+            EXPR = detail,
+            "ratio"     = c(0, 4),
+            "balance"   = max(abs(range(geau::so_ii_onrn[["balance"]]))) * c(-1, 1),
+            NULL
+        )
+
+        color = scales::cscale(
+            c(onrn_range, geau::so_ii_onrn[[detail]]),
+            onrn_palette,
+            trans = onrn_trans)
+        if (length(onrn_range) > 0) {
+            color = color[-seq(onrn_range)]
+        }
+        border = "grey80"
         plot(
-            geau::so_ii_clc[["geometry"]],
-            border = NA,
-            col = geau::so_ii_clc[["color"]],
+            geau::so_ii_collectivity[["geometry"]],
+            border = border,
+            col = color,
             add = TRUE
         )
 
+        if (sprintf("%s_min", detail) %in% names(geau::so_ii_onrn)) {
+            selection = c(detail, sprintf("%s_min", detail), sprintf("%s_max", detail))
+            temp = unique(geau::so_ii_onrn[selection])
+            temp = temp[order(temp[[detail]]), ]
+            text_legend = gsub("0 - 0", "0",
+                sprintf(
+                    "%s - %s",
+                    temp[[sprintf("%s_min", detail)]],
+                    temp[[sprintf("%s_max", detail)]]
+                )
+            )
+            value_legend = temp[[detail]]
+        }
+        if (detail %in% c("n_catnat", "ppri_year")) {
+            value_legend = round(
+                seq(
+                    min(geau::so_ii_onrn[[detail]], na.rm = TRUE),
+                    max(geau::so_ii_onrn[[detail]], na.rm = TRUE),
+                    length.out = 5
+                )
+            )
+            text_legend = value_legend
+        }
+        if (detail %in% c("balance")) {
+            value_legend = unique(
+                c(
+                    seq(min(geau::so_ii_onrn[[detail]]), 0, length.out = 4),
+                    seq(0, max(geau::so_ii_onrn[[detail]]), length.out = 4)
+                )
+            )
+            text_legend = formatC(
+                as.integer(signif(round(value_legend), 2)),
+                big.mark = " "
+            )
+        }
+        color_legend = scales::cscale(
+                c(onrn_range, value_legend),
+                onrn_palette,
+                trans = onrn_trans
+            )
+        if (length(onrn_range) > 0) {
+            color_legend = color_legend[-seq(onrn_range)]
+        }
+        title_onrn = switch(
+            EXPR = detail,
+            "n_catnat"  = "N arr\u00eat\u00e9s Cat-Nat (ONRN)",
+            "freq_sin"  = "Sinistre / Risque [1995-2018]",
+            "cost"      = "Co\u00fbt cumul\u00e9 (\u20AC) [1995-2018]",
+            "cost_hab"  = "Co\u00fbt / hab (\u20ac) [1995-2018]",
+            "cost_mean" = "Co\u00fbt / sinistre (\u20ac) [1995-2018]",
+            "ratio"     = "Co\u00fbt / Prime [1995-2018]",
+            "balance"   = "Co\u00fbt - Prime (\u20ac) [1995-2018]",
+            "ppri_year" = "Ann\u00e9e des PPRI",
+            NULL
+        )
+
         theme_legend = list(
-            title = "CLC (2018)",
-            legend = geau::clc_color[["label_fr"]],
+            title = title_onrn,
+            legend = text_legend,
             x = "topright",
             cex = .8,
             bg = "white",
             inset = 0.01,
-            fill = geau::clc_color[["color"]]
+            fill = color_legend,
+            border = border
         )
+        rm(text_legend)
     }
 
     if ("population" %in% theme) {
@@ -204,122 +446,6 @@ map_so_ii = function(
         )
     }
 
-    if ("catnat" %in% theme) {
-        if (missing(detail)) {
-            detail = dimnames(geau::so_ii_catnat)[["hazard"]]
-        }
-        detail = match.arg(
-            detail, 
-            dimnames(geau::so_ii_catnat)[["hazard"]],
-            several.ok = TRUE
-        )
-        border = NA
-        color = NA
-        if (!missing(year)) {
-            year = match.arg(
-                as.character(year),
-                dimnames(geau::so_ii_catnat)[["period"]]
-            )
-            border = "grey80"
-            catnat = apply(
-                geau::so_ii_catnat[, year, detail, drop = FALSE],
-                1:2,
-                sum
-            )
-            color = ifelse(
-                catnat > 0,
-                scales::alpha("grey80", .5),
-                NA
-            )
-            theme_legend = list(
-                title = sprintf("Cat-Nat %s", year),
-                legend = c("Sans d\u00e9claration", "Avec d\u00e9claration"),
-                x = "topright",
-                cex = .8,
-                bg = "white",
-                inset = 0.01,
-                fill = unique(color),
-                border = border
-            )
-        }
-
-        plot(
-            geau::so_ii_collectivity[["geometry"]],
-            border = border,
-            col = color,
-            add = TRUE
-        )
-    }
-
-    if ("hydro" %in% theme) {
-        if (missing(detail)) {
-            detail = "none"
-        }
-        detail = match.arg(
-            as.character(detail),
-            choices = c(
-                "none",
-                levels(geau::so_ii_hydro[["degre"]]),
-                levels(geau::so_ii_hydro[["type"]])
-            )
-        )
-        color = scales::alpha("blue", .3)
-        bg = scales::alpha("blue", .3)
-        border = NA
-        selection = seq(nrow(geau::so_ii_hydro))
-        theme_legend = list(
-            title = sprintf("R\u00e9seau hydrographique"),
-            legend = "\u00e9l\u00e9ment du r\u00e9seau",
-            x = "topright",
-            cex = .8,
-            bg = "white",
-            inset = 0.01,
-            col = color,
-            lwd = 1
-        )
-        if (detail %in% levels(geau::so_ii_hydro[["type"]])) {
-            selection  = as.character(geau::so_ii_hydro[["type"]]) == detail
-            theme_legend[["legend"]] = detail
-        }
-        if (detail %in% levels(geau::so_ii_hydro[["degre"]])) {
-            selection  = as.character(geau::so_ii_hydro[["degre"]]) <= detail
-        }
-        geometry = geau::so_ii_hydro[["geometry"]][selection]
-        lwd = 4 - as.numeric(geau::so_ii_hydro[["degre"]][selection])
-
-        plot(geometry, col = color, lwd = lwd, border = border, add = TRUE)
-    }
-
-    if ("catchment" %in% theme) {
-        if (missing(detail)) {
-            detail = "1"
-        }
-        detail = match.arg(
-            as.character(detail), 
-            choices = levels(geau::so_ii_catchment[["degre"]])
-        )
-        selection  = geau::so_ii_catchment[["degre"]] == detail
-        geometry = geau::so_ii_catchment[["geometry"]][selection]
-        catchment = as.factor(geau::so_ii_catchment[["catchment_name"]][selection])
-        color_legend = grDevices::hcl.colors(nlevels(catchment), "Pastel 1", alpha = .3)
-        color = color_legend[catchment]
-        border = "grey80"
-        lwd = 2
-        theme_legend = list(
-            title = sprintf("Bassin versant"),
-            legend = levels(catchment),
-            x = "topright",
-            cex = .8,
-            bg = "white",
-            inset = 0.01,
-            fill = color_legend,
-            border = border
-        )
-        if (detail == "3") rm(theme_legend)
-
-        plot(geometry, border = border, col = color, lwd = lwd, add = TRUE)
-    }
-
     if (!missing(dataset)) plot(dataset[["geometry"]], add = TRUE, ...)
 
     plot(geau::so_ii_limit, lwd = 2, add = TRUE)
@@ -344,9 +470,9 @@ map_so_ii = function(
         do.call(graphics::legend, dataset_legend)
     }
 
-    if (legend_theme == TRUE && exists("theme_legend")) {
+    if (legend_theme == TRUE && exists("theme_legend", inherits = FALSE)) {
         temp = do.call(graphics::legend, theme_legend)
-        if (exists("text_legend")) {
+        if (exists("text_legend", inherits = FALSE)) {
             graphics::text(
                 x = temp[["rect"]][["left"]] + temp[["rect"]][["w"]],
                 y = temp[["text"]][["y"]],
diff --git a/geau/data-raw/so_ii_onrn.R b/geau/data-raw/so_ii_onrn.R
new file mode 100644
index 0000000..a6118f0
--- /dev/null
+++ b/geau/data-raw/so_ii_onrn.R
@@ -0,0 +1,28 @@
+# code to prepare `so_ii_onrn` dataset goes here
+
+so_ii_onrn = read.csv2(
+    geau::current_version("data-common/so-ii/onrn"),
+    row.names = 1
+)
+class(so_ii_population) = "data.frame"
+rownames(so_ii_population) = so_ii_population[["CODGEO"]]
+selection = grep(
+    "PMUN|PSCDC|PTOT",
+    colnames(so_ii_population),
+    value = TRUE
+)
+so_ii_population = as.matrix(
+    so_ii_population[geau::so_ii_scope, selection]
+)
+year = gsub("PMUN", "20", selection)
+year = gsub("PTOT", "19", year)
+year = gsub("1919", "19", year)
+year = gsub("1918", "18", year)
+dimnames(so_ii_population)[[2]] = year
+
+# updating datasets
+
+# actual = setwd(file.path(system.file(package = "geau"), ".."))
+actual = setwd("geau")
+usethis::use_data(so_ii_population, internal = FALSE, overwrite = TRUE)
+setwd(actual)
diff --git a/geau/data/so_ii_onrn.rda b/geau/data/so_ii_onrn.rda
new file mode 100644
index 0000000000000000000000000000000000000000..5985ecbfe976d7619b844a785b0f048fdb6ff0eb
GIT binary patch
literal 2936
zcmYjMc{tPy7ye~tEW>oiE`8MuW3o@yHg3NrG&A-Ygt!exnJib~mT@t|j5UR_?;2z6
zX30(@`*Kr;EQur`CD|(B%e~L{Jm34r`<`>&bIx-P-qGWv)>#KE#bKgtAr(M=+1*3V
z?&fajPYwO4yUSa9rRBYR58KnC&QnGLNwUq$;Nibc>|c9nz-NZ<E4INTX)B#k4T<mJ
zuB~GklpcAnyL^3K+<gjNsAw(w{*d)Tv~G~i_^mq>J_KA#55#5{E;5CRzZVuU(&<0>
z@O=}|5FFI!{p>UZ4JhV9#j_b!LxVZoNN`^+@DqYehzS!w?1cb;kpEZzwE%=6hG<Bf
z9fp8n{C|yqSoi-}sAz8l!!OV?FJ5%v4i14s;2=O>*vDf&kN@e2F%e>E05FIE5RkL?
zO~O%vOh8^<kd+GvLqLzcMT2|v&jAqde;KeBiZKBUfhDeA81G>&pG{n(^N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r-f=%scG7=u>p6{<=y3Q=)Dx&f5cDvAzE+U~K459(Ut~?t|@)
z5o<#H?5dyp+gqvYyC!jhpf#NW3RbN*ds5BAse>z@wic@&p2e`{DA9^ab1gB6LbWTq
z=E0gz*GVC)om0A%_L{jSZ+Bv5x20o9YITQ82gpPy-_y|~=yd5E;3SynB-Sd67ucQo
OL@0zy9K7kQ1N;|l^gf9I

literal 0
HcmV?d00001

diff --git a/geau/man/map_so_ii.Rd b/geau/man/map_so_ii.Rd
index 63263ef..592e5ef 100644
--- a/geau/man/map_so_ii.Rd
+++ b/geau/man/map_so_ii.Rd
@@ -8,7 +8,7 @@
 map_so_ii(
   dataset,
   dataset_legend = NULL,
-  theme = c("none", "collectivity", "catchment", "catnat", "clc", "hydro",
+  theme = c("none", "collectivity", "catchment", "catnat", "clc", "hydro", "onrn",
     "population"),
   bar = TRUE,
   path = NULL,
@@ -59,6 +59,8 @@ and only the boundaries of collectivities are plotted.}
 levels of detail or "canal", "river", "waterbody" for types of
 hydrographic elements. If missing, "none" will be chosen, and
 everything is plotted.}
+\item{\strong{onrn}: detail must be chosen in "n_catnat", "freq_sin",
+"cost", "cost_hab", "cost_mean", "ratio", "balance", "ppri_year".}
 }
 }
 \subsection{year specification}{
diff --git a/geau/man/so_ii_clc.Rd b/geau/man/so_ii_clc.Rd
index 0d62e5c..2f08e4b 100644
--- a/geau/man/so_ii_clc.Rd
+++ b/geau/man/so_ii_clc.Rd
@@ -5,12 +5,16 @@
 \alias{so_ii_clc}
 \title{CLC information for so-ii}
 \format{
-sf object
+sf data.frame 1337 rows, 2 variables
+\describe{
+\item{clc_2018}{character, classification from CLC 2018}
+\item{color}{character, default color to be used to plot so_ii_clc}
+}
 }
 \usage{
 so_ii_clc
 }
 \description{
-A dataset containing the 2018 version of CLC information for so-ii
+A dataset containing the Corine Land Cover information on so-ii.
 }
 \keyword{datasets}
diff --git a/geau/man/so_ii_limit.Rd b/geau/man/so_ii_limit.Rd
index c54cc95..64c439b 100644
--- a/geau/man/so_ii_limit.Rd
+++ b/geau/man/so_ii_limit.Rd
@@ -6,22 +6,12 @@
 \title{Spatial perimeter of so-ii}
 \format{
 sfc_POLYGON of length 1
-
-sf data.frame 1337 rows, 2 variables
-\describe{
-\item{clc_2018}{character, classification from CLC 2018}
-\item{color}{character, default color to be used to plot so_ii_clc}
-}
 }
 \usage{
-so_ii_limit
-
 so_ii_limit
 }
 \description{
 A dataset containing the perimeter of so-ii.
-
-A dataset containing the Corine Land Cover information on so-ii.
 }
 \details{
 Basically, this dataset is obtained as
diff --git a/geau/man/so_ii_onrn.Rd b/geau/man/so_ii_onrn.Rd
new file mode 100644
index 0000000..0991fd9
--- /dev/null
+++ b/geau/man/so_ii_onrn.Rd
@@ -0,0 +1,50 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/data.r
+\docType{data}
+\name{so_ii_onrn}
+\alias{so_ii_onrn}
+\title{ONRN information for so-ii}
+\format{
+data.frame 78 rows, 23 variables
+\describe{
+\item{n_catnat}{Number of Cat Nat events}
+\item{freq_sin}{Number of claims divided by number of contracts
+for 1995 to 2018. freq_sin is calculated as the mean of freq_sin_min
+and freq_sin_max (range for each category).}
+\item{cost}{Cumulative cost of claims for 1995 to 2018. Cost is calculated
+as the mean of cost_min and cost_max (range for each category).}
+\item{cost_mean}{Mean cost of claims (cost divided by claims) for 1995 to
+2018. cost_mean is calculated as the mean of cost_mean_min and
+cost_mean_max (range for each category).}
+\item{cost_hab}{Cost divided by the population for 1995 to 2018. cost_hab
+is calculated as the mean of cost_hab_min and cost_hab_max (range for
+each category).}
+\item{ratio}{Cost divided by premium for 1995 to 2018. ratio is calculated
+as the mean of cost_hab_min and cost_hab_max (range for each
+category).}
+\item{balance}{Cost minus premium for 1995 to 2018. This is an estimation
+made by so-ii team by considering a mean premium for each habitant
+of 24.92829 euro per habitant (total premium in 2018 divided by
+total population)}
+\item{ppri_year}{Year given for the last PPRI.}
+\item{ppri_state}{State of the last PPRI.}
+\item{ppri_state_sub}{Some details on the state of the last PPRI.}
+\item{ppri_state_age}{State of the last PPRI for age information.}
+\item{ppri_age_min}{Lower boundary for the age of the PPRI.}
+\item{ppri_age_min}{Upper boundary for the age of the PPRI..}
+}
+}
+\source{
+\url{https://www.georisques.gouv.fr/articles-risques/acceder-aux-indicateurs-sinistralite}
+}
+\usage{
+so_ii_onrn
+}
+\description{
+A dataset containing part of the information available at the ONRN for so-ii
+communities. The information chosen is exclusively related to floods. It is
+mainly related to impacts and therefore to the claims in from the Cat-Nat
+system. These data on claims are taken from the CCR, the others from the
+gaspar database.
+}
+\keyword{datasets}
-- 
GitLab