From 1baf02629ec9336d180c7a490c7ec92dabb7f490 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Grelot?= <frederic.grelot@irstea.fr>
Date: Fri, 4 Feb 2022 09:09:42 +0100
Subject: [PATCH] so.ii Version 1.0.16.0
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- renommage de la library en so.ii
- ajout de la fonction plot_legend pour générer des légendes indépendamment des cartes
---
 dev/package.development.R                     |   4 +-
 map/map_so_ii.rmd                             |  48 +++++--
 {geau => so.ii}/.Rbuildignore                 |   0
 {geau => so.ii}/.gitignore                    |   0
 {geau => so.ii}/DESCRIPTION                   |   6 +-
 {geau => so.ii}/LICENSE.md                    |   0
 {geau => so.ii}/NAMESPACE                     |   1 +
 {geau => so.ii}/R/add.inset.R                 |   0
 {geau => so.ii}/R/current_version.r           |   0
 {geau => so.ii}/R/data.r                      |   0
 {geau => so.ii}/R/estimate_catnat_freq.R      |   0
 {geau => so.ii}/R/format_presence.R           |   0
 {geau => so.ii}/R/kable_units.r               |   0
 {geau => so.ii}/R/map_so_ii.r                 | 117 +++++++++---------
 so.ii/R/plot_legend.r                         |  76 ++++++++++++
 {geau => so.ii}/data-raw/so_ii_catchment.R    |   0
 {geau => so.ii}/data-raw/so_ii_catnat.R       |   0
 {geau => so.ii}/data-raw/so_ii_collectivity.R |   0
 {geau => so.ii}/data-raw/so_ii_hydro.R        |   0
 {geau => so.ii}/data-raw/so_ii_montpellier.R  |   0
 {geau => so.ii}/data-raw/so_ii_onrn.R         |   0
 {geau => so.ii}/data-raw/so_ii_osm.R          |   0
 {geau => so.ii}/data-raw/so_ii_population.R   |   0
 {geau => so.ii}/data-raw/so_ii_scope.R        |   0
 {geau => so.ii}/data/clc_color.rda            | Bin
 {geau => so.ii}/data/so_ii_catchment.rda      | Bin
 {geau => so.ii}/data/so_ii_catnat.rda         | Bin
 {geau => so.ii}/data/so_ii_clc.rda            | Bin
 {geau => so.ii}/data/so_ii_collectivity.rda   | Bin
 {geau => so.ii}/data/so_ii_hydro.rda          | Bin
 {geau => so.ii}/data/so_ii_limit.rda          | Bin
 {geau => so.ii}/data/so_ii_montpellier.rda    | Bin
 {geau => so.ii}/data/so_ii_onrn.rda           | Bin
 {geau => so.ii}/data/so_ii_population.rda     | Bin
 {geau => so.ii}/data/so_ii_scope.rda          | Bin
 {geau => so.ii}/inst/extdata/so_ii_osm.tif    | Bin
 .../inst/extdata/so_ii_osm.tif.aux.xml        |   0
 {geau => so.ii}/man/add.inset.Rd              |   0
 {geau => so.ii}/man/clc_color.Rd              |   0
 {geau => so.ii}/man/current_version.Rd        |   0
 {geau => so.ii}/man/estimate_catnat_freq.Rd   |   0
 {geau => so.ii}/man/format_presence.Rd        |   2 +-
 {geau => so.ii}/man/kable_units.Rd            |   0
 {geau => so.ii}/man/map_so_ii.Rd              |   0
 so.ii/man/plot_legend.Rd                      |  51 ++++++++
 {geau => so.ii}/man/so_ii_catchment.Rd        |   0
 {geau => so.ii}/man/so_ii_catnat.Rd           |   0
 {geau => so.ii}/man/so_ii_clc.Rd              |   0
 {geau => so.ii}/man/so_ii_collectivity.Rd     |   0
 {geau => so.ii}/man/so_ii_hydro.Rd            |   0
 {geau => so.ii}/man/so_ii_limit.Rd            |   0
 {geau => so.ii}/man/so_ii_montpellier.Rd      |   0
 {geau => so.ii}/man/so_ii_onrn.Rd             |   0
 {geau => so.ii}/man/so_ii_population.Rd       |   0
 {geau => so.ii}/man/so_ii_scope.Rd            |   0
 55 files changed, 230 insertions(+), 75 deletions(-)
 rename {geau => so.ii}/.Rbuildignore (100%)
 rename {geau => so.ii}/.gitignore (100%)
 rename {geau => so.ii}/DESCRIPTION (89%)
 rename {geau => so.ii}/LICENSE.md (100%)
 rename {geau => so.ii}/NAMESPACE (89%)
 rename {geau => so.ii}/R/add.inset.R (100%)
 rename {geau => so.ii}/R/current_version.r (100%)
 rename {geau => so.ii}/R/data.r (100%)
 rename {geau => so.ii}/R/estimate_catnat_freq.R (100%)
 rename {geau => so.ii}/R/format_presence.R (100%)
 rename {geau => so.ii}/R/kable_units.r (100%)
 rename {geau => so.ii}/R/map_so_ii.r (85%)
 create mode 100644 so.ii/R/plot_legend.r
 rename {geau => so.ii}/data-raw/so_ii_catchment.R (100%)
 rename {geau => so.ii}/data-raw/so_ii_catnat.R (100%)
 rename {geau => so.ii}/data-raw/so_ii_collectivity.R (100%)
 rename {geau => so.ii}/data-raw/so_ii_hydro.R (100%)
 rename {geau => so.ii}/data-raw/so_ii_montpellier.R (100%)
 rename {geau => so.ii}/data-raw/so_ii_onrn.R (100%)
 rename {geau => so.ii}/data-raw/so_ii_osm.R (100%)
 rename {geau => so.ii}/data-raw/so_ii_population.R (100%)
 rename {geau => so.ii}/data-raw/so_ii_scope.R (100%)
 rename {geau => so.ii}/data/clc_color.rda (100%)
 rename {geau => so.ii}/data/so_ii_catchment.rda (100%)
 rename {geau => so.ii}/data/so_ii_catnat.rda (100%)
 rename {geau => so.ii}/data/so_ii_clc.rda (100%)
 rename {geau => so.ii}/data/so_ii_collectivity.rda (100%)
 rename {geau => so.ii}/data/so_ii_hydro.rda (100%)
 rename {geau => so.ii}/data/so_ii_limit.rda (100%)
 rename {geau => so.ii}/data/so_ii_montpellier.rda (100%)
 rename {geau => so.ii}/data/so_ii_onrn.rda (100%)
 rename {geau => so.ii}/data/so_ii_population.rda (100%)
 rename {geau => so.ii}/data/so_ii_scope.rda (100%)
 rename {geau => so.ii}/inst/extdata/so_ii_osm.tif (100%)
 rename {geau => so.ii}/inst/extdata/so_ii_osm.tif.aux.xml (100%)
 rename {geau => so.ii}/man/add.inset.Rd (100%)
 rename {geau => so.ii}/man/clc_color.Rd (100%)
 rename {geau => so.ii}/man/current_version.Rd (100%)
 rename {geau => so.ii}/man/estimate_catnat_freq.Rd (100%)
 rename {geau => so.ii}/man/format_presence.Rd (89%)
 rename {geau => so.ii}/man/kable_units.Rd (100%)
 rename {geau => so.ii}/man/map_so_ii.Rd (100%)
 create mode 100644 so.ii/man/plot_legend.Rd
 rename {geau => so.ii}/man/so_ii_catchment.Rd (100%)
 rename {geau => so.ii}/man/so_ii_catnat.Rd (100%)
 rename {geau => so.ii}/man/so_ii_clc.Rd (100%)
 rename {geau => so.ii}/man/so_ii_collectivity.Rd (100%)
 rename {geau => so.ii}/man/so_ii_hydro.Rd (100%)
 rename {geau => so.ii}/man/so_ii_limit.Rd (100%)
 rename {geau => so.ii}/man/so_ii_montpellier.Rd (100%)
 rename {geau => so.ii}/man/so_ii_onrn.Rd (100%)
 rename {geau => so.ii}/man/so_ii_population.Rd (100%)
 rename {geau => so.ii}/man/so_ii_scope.Rd (100%)

diff --git a/dev/package.development.R b/dev/package.development.R
index ceee3bd..5b9abcb 100644
--- a/dev/package.development.R
+++ b/dev/package.development.R
@@ -1,4 +1,4 @@
-package = "geau" ; devtools::document(package) ; devtools::load_all(package)
+package = "so.ii" ; devtools::document(package) ; devtools::load_all(package)
 
 ### Vignettes
 # setwd(package):usethis::use_vignette(package);setwd("..")
@@ -15,4 +15,4 @@ devtools::build(package, path = "library", vignettes = TRUE)
 
 ### install -> sudo
 # devtools::install_local(package)
-sudo su - -c "R -e \"devtools::install_gitlab('geau-inondation/geau-utility',  subdir = 'geau', host = 'gitlab.irstea.fr', upgrade = 'never', auth_token = 'rCEfcrjoms9UNykCuM5c')\""  # nolint
\ No newline at end of file
+sudo su - -c "R -e \"devtools::install_gitlab('geau-inondation/geau-utility',  subdir = 'so.ii', host = 'gitlab.irstea.fr', upgrade = 'never', auth_token = 'rCEfcrjoms9UNykCuM5c')\""  # nolint
\ No newline at end of file
diff --git a/map/map_so_ii.rmd b/map/map_so_ii.rmd
index fdfde95..63b35a6 100644
--- a/map/map_so_ii.rmd
+++ b/map/map_so_ii.rmd
@@ -1,7 +1,7 @@
 
 ```{r library}
 library(sf)
-library(geau)
+library(so.ii)
 ```
 
 ```{r update-theme}
@@ -12,22 +12,46 @@ map_so_ii(theme = "collectivity", path = sprintf(path, "collectivity"))
 map_so_ii(theme = "collectivity", theme_legend = TRUE, detail = "syndicate", path = sprintf(path, "syndicate"))
 map_so_ii(theme = "collectivity", theme_legend = TRUE, detail = "epci", path = sprintf(path, "epci"))
 map_so_ii(theme = "clc", theme_legend = TRUE, path = sprintf(path, "clc"))
-map_so_ii(theme = "population", theme_legend = TRUE, path = sprintf(path, "population"))
+map_so_ii(theme = "population", main = "population [2019]", theme_legend = TRUE, path = sprintf(path, "population"))
 map_so_ii(theme = "population", year = 1931, theme_legend = TRUE, path = sprintf(path, "population-1931"))
 map_so_ii(theme = "population", year = 2018:2019, theme_legend = TRUE, path = sprintf(path, "population-last"))
 map_so_ii(theme = "population", year = 2014:2019, theme_legend = TRUE, path = sprintf(path, "population-last-5"))
-map_so_ii(theme = "catnat", theme_legend = TRUE, path = sprintf(path, "catnat"))
-map_so_ii(theme = "catnat", year = 2000:2019, theme_legend = TRUE, path = sprintf(path, "catnat-2000-2019"))
-map_so_ii(theme = "catnat", year = 2021, theme_legend = TRUE, path = sprintf(path, "catnat-2021"))
+
+
 map_so_ii(so_ii_hydro[as.character(so_ii_hydro$degre) <= 1, ], col = scales::colour_ramp(c("white", "blue"))(.5), border = NA, theme = "catchment", theme_legend = TRUE, path = sprintf(path, "catchment"))
 map_so_ii(so_ii_hydro[as.character(so_ii_hydro$degre) <= 2, ], col = scales::colour_ramp(c("white", "blue"))(.5), border = NA, theme = "catchment", detail = 2, theme_legend = TRUE, path = sprintf(path, "catchment_sub"))
-map_so_ii(theme = "onrn", detail = "freq_sin", theme_legend = TRUE, path = sprintf(path, "freq_sin"))
-map_so_ii(theme = "onrn", detail = "cost", theme_legend = TRUE, path = sprintf(path, "cost"))
-map_so_ii(theme = "onrn", detail = "cost_hab", theme_legend = TRUE, path = sprintf(path, "cost_hab"))
-map_so_ii(theme = "onrn", detail = "cost_mean", theme_legend = TRUE, path = sprintf(path, "cost_mean"))
-map_so_ii(theme = "onrn", detail = "ratio", theme_legend = TRUE, path = sprintf(path, "ratio"))
-map_so_ii(theme = "onrn", detail = "balance", theme_legend = TRUE, path = sprintf(path, "balance"))
-map_so_ii(theme = "onrn", detail = "ppri_year", theme_legend = TRUE, path = sprintf(path, "ppri_year"))
+
+# Cat-Nat
+period = range(dimnames(so_ii_catnat)[["period"]])
+map_so_ii(
+    theme = "catnat",
+    main = sprintf("Cat-Nat [%s]", paste(period, collapse = "-")),
+    theme_legend = TRUE,
+    path = sprintf(path, "catnat"))
+period = range(2000:2019)
+map_so_ii(
+    theme = "catnat",
+    year = period,
+    main = sprintf("Cat-Nat [%s]", paste(period, collapse = "-")),
+    theme_legend = TRUE,
+    path = sprintf(path, "catnat-2000-2019"))
+period = 2021
+map_so_ii(
+    theme = "catnat",
+    year = period
+    main = sprintf("Cat-Nat [%s]", paste(period, collapse = "-")),
+    theme_legend = TRUE,
+    path = sprintf(path, "catnat-2021"))
+
+# ONRN
+
+map_so_ii(theme = "onrn", main = "sinistre / risque", detail = "freq_sin", theme_legend = TRUE, path = sprintf(path, "freq_sin"))
+map_so_ii(theme = "onrn", main = "€ somme", detail = "cost", theme_legend = TRUE, path = sprintf(path, "cost"))
+map_so_ii(theme = "onrn", main = "€ / habitant", detail = "cost_hab", theme_legend = TRUE, path = sprintf(path, "cost_hab"))
+map_so_ii(theme = "onrn", main = "€ / sinistre", detail = "cost_mean", theme_legend = TRUE, path = sprintf(path, "cost_mean"))
+map_so_ii(theme = "onrn", main = "sinistre / prime", detail = "ratio", theme_legend = TRUE, path = sprintf(path, "ratio"))
+map_so_ii(theme = "onrn", main = "sinistre - prime", detail = "balance", theme_legend = TRUE, path = sprintf(path, "balance"))
+map_so_ii(theme = "onrn", main = "PPRI", detail = "ppri_year", theme_legend = TRUE, path = sprintf(path, "ppri_year"))
 ```
 
 ```{r update-rex-example}
diff --git a/geau/.Rbuildignore b/so.ii/.Rbuildignore
similarity index 100%
rename from geau/.Rbuildignore
rename to so.ii/.Rbuildignore
diff --git a/geau/.gitignore b/so.ii/.gitignore
similarity index 100%
rename from geau/.gitignore
rename to so.ii/.gitignore
diff --git a/geau/DESCRIPTION b/so.ii/DESCRIPTION
similarity index 89%
rename from geau/DESCRIPTION
rename to so.ii/DESCRIPTION
index c688320..d645a8e 100644
--- a/geau/DESCRIPTION
+++ b/so.ii/DESCRIPTION
@@ -1,6 +1,6 @@
-Package: geau
-Title: Utilities very useful to share within geau-inondation team
-Version: 1.0.15.0
+Package: so.ii
+Title: Utilities very useful to share within so_ii team
+Version: 1.0.16.0
 Authors@R:
     c(
         person(given = "Frédéric",
diff --git a/geau/LICENSE.md b/so.ii/LICENSE.md
similarity index 100%
rename from geau/LICENSE.md
rename to so.ii/LICENSE.md
diff --git a/geau/NAMESPACE b/so.ii/NAMESPACE
similarity index 89%
rename from geau/NAMESPACE
rename to so.ii/NAMESPACE
index 879c502..6322ac9 100644
--- a/geau/NAMESPACE
+++ b/so.ii/NAMESPACE
@@ -6,3 +6,4 @@ export(estimate_catnat_freq)
 export(format_presence)
 export(kable_units)
 export(map_so_ii)
+export(plot_legend)
diff --git a/geau/R/add.inset.R b/so.ii/R/add.inset.R
similarity index 100%
rename from geau/R/add.inset.R
rename to so.ii/R/add.inset.R
diff --git a/geau/R/current_version.r b/so.ii/R/current_version.r
similarity index 100%
rename from geau/R/current_version.r
rename to so.ii/R/current_version.r
diff --git a/geau/R/data.r b/so.ii/R/data.r
similarity index 100%
rename from geau/R/data.r
rename to so.ii/R/data.r
diff --git a/geau/R/estimate_catnat_freq.R b/so.ii/R/estimate_catnat_freq.R
similarity index 100%
rename from geau/R/estimate_catnat_freq.R
rename to so.ii/R/estimate_catnat_freq.R
diff --git a/geau/R/format_presence.R b/so.ii/R/format_presence.R
similarity index 100%
rename from geau/R/format_presence.R
rename to so.ii/R/format_presence.R
diff --git a/geau/R/kable_units.r b/so.ii/R/kable_units.r
similarity index 100%
rename from geau/R/kable_units.r
rename to so.ii/R/kable_units.r
diff --git a/geau/R/map_so_ii.r b/so.ii/R/map_so_ii.r
similarity index 85%
rename from geau/R/map_so_ii.r
rename to so.ii/R/map_so_ii.r
index a053910..56fbf1f 100644
--- a/geau/R/map_so_ii.r
+++ b/so.ii/R/map_so_ii.r
@@ -110,11 +110,14 @@ map_so_ii = function(
     theme = match.arg(theme)
 
     if (!is.null(path)) {
+        width = 18
+        height = 18
         switch(
             EXPR = tolower(tools::file_ext(path)),
-            "pdf" = grDevices::cairo_pdf(path),
-            "png" = grDevices::png(path),
-            "svg" = grDevices::svg(path),
+            "pdf" = grDevices::cairo_pdf(path, width = width / 2.54, height = height / 2.54),
+            "png" = grDevices::png(path, width = width, height = height, units = "cm"),
+            "jpg" = grDevices::jpeg(path, width = width, height = height, units = "cm"),
+            "svg" = grDevices::svg(path, width = width / 2.54, height = height / 2.54),
             stop(sprintf("%s not recognized", tolower(tools::file_ext(path))))
         )
         on.exit(grDevices::dev.off())
@@ -122,7 +125,7 @@ map_so_ii = function(
 
     ## Init map
     graphics::par(mai = c(.65, .60, .50, .15))
-    plot(geau::so_ii_limit, axes = TRUE, main = list(...)[["main"]], cex.main = 3)
+    plot(so.ii::so_ii_limit, axes = TRUE, main = list(...)[["main"]], cex.main = 2.5)
 
     ## Plot theme if any, return theme_legend
     theme_legend = switch(
@@ -142,7 +145,7 @@ map_so_ii = function(
     if (!missing(dataset)) plot(dataset[["geometry"]], add = TRUE, ...)
 
     ## Make so_ii_limit visible
-    plot(geau::so_ii_limit, lwd = 2, add = TRUE)
+    plot(so.ii::so_ii_limit, lwd = 2, add = TRUE)
 
     ## Plot bar
     if (bar == TRUE) {
@@ -192,12 +195,12 @@ map_theme_catchment = function(detail, add_legend) {
     }
     detail = match.arg(
         as.character(detail), 
-        choices = levels(geau::so_ii_catchment[["degre"]])
+        choices = levels(so.ii::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])
+    selection  = so.ii::so_ii_catchment[["degre"]] == detail
+    geometry = so.ii::so_ii_catchment[["geometry"]][selection]
+    catchment = as.factor(so.ii::so_ii_catchment[["catchment_name"]][selection])
     color_legend = grDevices::hcl.colors(nlevels(catchment), "Pastel 1", alpha = .3)
     color = color_legend[catchment]
     border = "grey80"
@@ -223,25 +226,25 @@ map_theme_catchment = function(detail, add_legend) {
 
 map_theme_catnat = function(detail, year, add_legend) {
     if (missing(detail)) {
-        detail = dimnames(geau::so_ii_catnat)[["hazard"]]
+        detail = dimnames(so.ii::so_ii_catnat)[["hazard"]]
     }
     detail = match.arg(
         detail, 
-        dimnames(geau::so_ii_catnat)[["hazard"]],
+        dimnames(so.ii::so_ii_catnat)[["hazard"]],
         several.ok = TRUE
     )
 
     if (missing(year)) {
-        year = range(dimnames(geau::so_ii_catnat)[["period"]])
+        year = range(dimnames(so.ii::so_ii_catnat)[["period"]])
     }
     year = match.arg(
         as.character(year),
-        dimnames(geau::so_ii_catnat)[["period"]],
+        dimnames(so.ii::so_ii_catnat)[["period"]],
         several.ok = TRUE
     )
     year = as.character(seq(min(year), max(year)))
     catnat = apply(
-        geau::so_ii_catnat[, year, detail, drop = FALSE],
+        so.ii::so_ii_catnat[, year, detail, drop = FALSE],
         1,
         sum
     )
@@ -253,7 +256,7 @@ map_theme_catnat = function(detail, year, add_legend) {
         catnat_palette
     )[-1]
     plot(
-        geau::so_ii_collectivity[["geometry"]],
+        so.ii::so_ii_collectivity[["geometry"]],
         border = border,
         col = color,
         add = TRUE
@@ -296,20 +299,20 @@ map_theme_catnat = function(detail, year, add_legend) {
 
 map_theme_clc = function(add_legend) {
     plot(
-        geau::so_ii_clc[["geometry"]],
+        so.ii::so_ii_clc[["geometry"]],
         border = NA,
-        col = geau::so_ii_clc[["color"]],
+        col = so.ii::so_ii_clc[["color"]],
         add = TRUE
     )
 
     theme_legend = list(
         title = "CLC (2018)",
-        legend = geau::clc_color[["label_fr"]],
+        legend = so.ii::clc_color[["label_fr"]],
         x = "topright",
         cex = .8,
         bg = "white",
         inset = 0.01,
-        fill = geau::clc_color[["color"]]
+        fill = so.ii::clc_color[["color"]]
     )
 
     if (add_legend == TRUE) {
@@ -341,13 +344,13 @@ map_theme_collectivity = function(detail, add_legend)  {
         fill = color,
         border = border
     )
-    geometry = geau::so_ii_collectivity[["geometry"]]
+    geometry = so.ii::so_ii_collectivity[["geometry"]]
     plot(geometry, border = border, col = color, add = TRUE)
     
     if (detail %in% c("syble", "syndicate")) {
         color_legend = scales::alpha("orange", .3)
         color = ifelse(
-            geau::so_ii_collectivity[["syble"]],
+            so.ii::so_ii_collectivity[["syble"]],
             color_legend,
             NA
         )
@@ -358,7 +361,7 @@ map_theme_collectivity = function(detail, add_legend)  {
     if (detail %in% c("symbo", "syndicate")) {
         color_legend = scales::alpha("green", .3)
         color = ifelse(
-            geau::so_ii_collectivity[["symbo"]],
+            so.ii::so_ii_collectivity[["symbo"]],
             color_legend,
             NA
         )
@@ -367,7 +370,7 @@ map_theme_collectivity = function(detail, add_legend)  {
         theme_legend[["fill"]] = c(theme_legend[["fill"]], color_legend) 
     }
     if (detail == "epci") {
-        epci = as.factor(geau::so_ii_collectivity[["epci_name"]])
+        epci = as.factor(so.ii::so_ii_collectivity[["epci_name"]])
         color_legend = grDevices::hcl.colors(nlevels(epci), "Lisbon", alpha = .3)
         color = color_legend[epci]
         plot(geometry, border = border, col = color, add = TRUE)
@@ -390,14 +393,14 @@ map_theme_hydro = function(detail, add_legend) {
         as.character(detail),
         choices = c(
             "none",
-            levels(geau::so_ii_hydro[["degre"]]),
-            levels(geau::so_ii_hydro[["type"]])
+            levels(so.ii::so_ii_hydro[["degre"]]),
+            levels(so.ii::so_ii_hydro[["type"]])
         )
     )
     color = scales::alpha("blue", .3)
     bg = scales::alpha("blue", .3)
     border = NA
-    selection = seq(nrow(geau::so_ii_hydro))
+    selection = seq(nrow(so.ii::so_ii_hydro))
     theme_legend = list(
         title = sprintf("R\u00e9seau hydrographique"),
         legend = "\u00e9l\u00e9ment du r\u00e9seau",
@@ -408,15 +411,15 @@ map_theme_hydro = function(detail, add_legend) {
         col = color,
         lwd = 1
     )
-    if (detail %in% levels(geau::so_ii_hydro[["type"]])) {
-        selection  = as.character(geau::so_ii_hydro[["type"]]) == detail
+    if (detail %in% levels(so.ii::so_ii_hydro[["type"]])) {
+        selection  = as.character(so.ii::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
+    if (detail %in% levels(so.ii::so_ii_hydro[["degre"]])) {
+        selection  = as.character(so.ii::so_ii_hydro[["degre"]]) <= detail
     }
-    geometry = geau::so_ii_hydro[["geometry"]][selection]
-    lwd = 4 - as.numeric(geau::so_ii_hydro[["degre"]][selection])
+    geometry = so.ii::so_ii_hydro[["geometry"]][selection]
+    lwd = 4 - as.numeric(so.ii::so_ii_hydro[["degre"]][selection])
 
     plot(geometry, col = color, lwd = lwd, border = border, add = TRUE)
 
@@ -433,7 +436,7 @@ map_theme_onrn = function(detail, add_legend) {
     }
     detail = match.arg(
         as.character(detail),
-        sort(colnames(geau::so_ii_onrn)[1:8])
+        sort(colnames(so.ii::so_ii_onrn)[1:8])
     )
 
     onrn_palette = switch(
@@ -463,12 +466,12 @@ map_theme_onrn = function(detail, add_legend) {
     onrn_range = switch(
         EXPR = detail,
         "ratio"     = c(0, 4),
-        "balance"   = max(abs(range(geau::so_ii_onrn[["balance"]]))) * c(-1, 1),
+        "balance"   = max(abs(range(so.ii::so_ii_onrn[["balance"]]))) * c(-1, 1),
         NULL
     )
 
     color = scales::cscale(
-        c(onrn_range, geau::so_ii_onrn[[detail]]),
+        c(onrn_range, so.ii::so_ii_onrn[[detail]]),
         onrn_palette,
         trans = onrn_trans)
     if (length(onrn_range) > 0) {
@@ -476,15 +479,15 @@ map_theme_onrn = function(detail, add_legend) {
     }
     border = "grey80"
     plot(
-        geau::so_ii_collectivity[["geometry"]],
+        so.ii::so_ii_collectivity[["geometry"]],
         border = border,
         col = color,
         add = TRUE
     )
 
-    if (sprintf("%s_min", detail) %in% names(geau::so_ii_onrn)) {
+    if (sprintf("%s_min", detail) %in% names(so.ii::so_ii_onrn)) {
         selection = c(detail, sprintf("%s_min", detail), sprintf("%s_max", detail))
-        temp = unique(geau::so_ii_onrn[selection])
+        temp = unique(so.ii::so_ii_onrn[selection])
         temp = temp[order(temp[[detail]]), ]
         text_legend = gsub("0 - 0", "0",
             sprintf(
@@ -498,8 +501,8 @@ map_theme_onrn = function(detail, add_legend) {
     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),
+                min(so.ii::so_ii_onrn[[detail]], na.rm = TRUE),
+                max(so.ii::so_ii_onrn[[detail]], na.rm = TRUE),
                 length.out = 5
             )
         )
@@ -508,8 +511,8 @@ map_theme_onrn = function(detail, add_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)
+                seq(min(so.ii::so_ii_onrn[[detail]]), 0, length.out = 4),
+                seq(0, max(so.ii::so_ii_onrn[[detail]]), length.out = 4)
             )
         )
         text_legend = formatC(
@@ -574,11 +577,11 @@ map_theme_osm = function() {
 
 map_theme_population = function(detail, year, add_legend) {
     if (missing(year)) {
-        year = utils::tail(sort(colnames(geau::so_ii_population)), 1)
+        year = utils::tail(sort(colnames(so.ii::so_ii_population)), 1)
     }
     year = match.arg(
         as.character(year),
-        sort(colnames(geau::so_ii_population)),
+        sort(colnames(so.ii::so_ii_population)),
         several.ok = TRUE
     )
 
@@ -588,21 +591,21 @@ map_theme_population = function(detail, year, add_legend) {
         pop_palette = scales::colour_ramp(c("white", "red"), alpha = .5)
         color = matrix(
             scales::cscale(
-                geau::so_ii_population,
+                so.ii::so_ii_population,
                 pop_palette,
                 trans = scales::log_trans()),
-            nrow = nrow(geau::so_ii_population),
-            dimnames = dimnames(geau::so_ii_population)
+            nrow = nrow(so.ii::so_ii_population),
+            dimnames = dimnames(so.ii::so_ii_population)
         )
 
         plot(
-            geau::so_ii_collectivity[["geometry"]],
+            so.ii::so_ii_collectivity[["geometry"]],
             border = border,
             col = color[ , year],
             add = TRUE
         )
-        max_pop = max(geau::so_ii_population[ , year])
-        min_pop = min(geau::so_ii_population[ , year])
+        max_pop = max(so.ii::so_ii_population[ , year])
+        min_pop = min(so.ii::so_ii_population[ , year])
         base = 10
 
         value_legend = unique(c(
@@ -611,7 +614,7 @@ map_theme_population = function(detail, year, add_legend) {
             max_pop
         ))
         color_legend = scales::cscale(
-                c(range(geau::so_ii_population), value_legend),
+                c(range(so.ii::so_ii_population), value_legend),
                 pop_palette,
                 trans = scales::log_trans()
             )[-(1:2)]
@@ -646,11 +649,11 @@ map_theme_population = function(detail, year, add_legend) {
         )
         pop_data = switch(
             EXPR = detail,
-            "absolute" = geau::so_ii_population[ , year[2]] -
-                geau::so_ii_population[ , year[1]],
-            "relative"  = (geau::so_ii_population[ , year[2]] -
-                geau::so_ii_population[ , year[1]]) /
-                geau::so_ii_population[ , year[1]]
+            "absolute" = so.ii::so_ii_population[ , year[2]] -
+                so.ii::so_ii_population[ , year[1]],
+            "relative"  = (so.ii::so_ii_population[ , year[2]] -
+                so.ii::so_ii_population[ , year[1]]) /
+                so.ii::so_ii_population[ , year[1]]
         )
         range_data = max(abs(range(pop_data))) * c(-1, 1)
         pop_trans = switch(
@@ -665,7 +668,7 @@ map_theme_population = function(detail, year, add_legend) {
             trans = pop_trans
         )[-(1:2)]
         plot(
-            geau::so_ii_collectivity[["geometry"]],
+            so.ii::so_ii_collectivity[["geometry"]],
             border = border,
             col = color,
             add = TRUE
diff --git a/so.ii/R/plot_legend.r b/so.ii/R/plot_legend.r
new file mode 100644
index 0000000..e698943
--- /dev/null
+++ b/so.ii/R/plot_legend.r
@@ -0,0 +1,76 @@
+#' @title Plot a legend independently of a map
+#'
+#' @details
+#' \subsection{path specification}{
+#' Depending on the extension a device is chosen.
+#' \itemize{
+#'   \item{\strong{pdf}: grDevices::cairo_pdf}
+#'   \item{\strong{png}: grDevices::png}
+#'   \item{\strong{svg}: grDevices::svg}
+#' }
+#' If path is NULL, standard plotting is used. If an extension is not managed,
+#' an error is raised.
+#' }
+#'
+#' @param dataset_legend list of parameters to be passed to legend
+#' @param path character, the name of the file to save the plot. Graphical
+#'  device is chosen depending on extension. See details.
+#' @param horiz logical, should the legend be horizontal
+#' @param add logical, should the legend be added to the current plot
+#'
+#' @return Nothing useful.
+#'
+#' @export plot_legend
+#'
+#' @encoding UTF-8
+#' @author Frédéric Grelot
+#'
+#' @examples
+#'
+#' dataset_legend = list(
+#'  title = "Beatutiful legend",
+#'  legend = c("red circle", "black square", "blue diamond"),
+#'  pch = 21:23,
+#'  pt.bg = c("red", "black", "blue")
+#' )
+#' plot_legend(dataset_legend)
+#' plot_legend(dataset_legend, horiz = FALSE)
+
+plot_legend = function(dataset_legend, path = NULL, horiz = TRUE, add = FALSE) {
+    dataset_legend[["horiz"]] = horiz
+
+    if (add == FALSE) {
+        if (!is.null(path)) {
+            switch(
+                EXPR = tolower(tools::file_ext(path)),
+                "pdf" = grDevices::cairo_pdf(path),
+                "png" = grDevices::png(path),
+                "jpg" = grDevices::jpeg(path),
+                "svg" = grDevices::svg(path),
+                stop(sprintf("%s not recognized", tolower(tools::file_ext(path))))
+            )
+            on.exit(grDevices::dev.off())
+
+            dataset_legend[["x"]] = "center"
+            graphics::par(mai = c(0, 0, 0, 0))
+            plot(NULL, axes = FALSE, ann = FALSE, xlim = 0:1, ylim = 0:1)
+            dimension = do.call(graphics::legend, dataset_legend)
+            grDevices::dev.off()
+
+            width = dimension[["rect"]][["w"]]
+            height = dimension[["rect"]][["h"]]
+            switch(
+                EXPR = tolower(tools::file_ext(path)),
+                "pdf" = grDevices::cairo_pdf(path, width = width * 7.5, height = height * 7.5),
+                "png" = grDevices::png(path, width = round(width * 500), height = round(height * 500)),
+                "jpg" = grDevices::jpeg(path, width = round(width * 500), height = round(height * 500)),
+                "svg" = grDevices::svg(path, width = width * 7.5, height = height * 7.5)
+            )
+        }
+
+        old_par = graphics::par(mai = c(0, 0, 0, 0))
+        dataset_legend[["x"]] = "center"
+        plot(NULL, axes = FALSE, ann = FALSE, xlim = 0:1, ylim = 0:1)
+    }
+    do.call(graphics::legend, dataset_legend)
+}
\ No newline at end of file
diff --git a/geau/data-raw/so_ii_catchment.R b/so.ii/data-raw/so_ii_catchment.R
similarity index 100%
rename from geau/data-raw/so_ii_catchment.R
rename to so.ii/data-raw/so_ii_catchment.R
diff --git a/geau/data-raw/so_ii_catnat.R b/so.ii/data-raw/so_ii_catnat.R
similarity index 100%
rename from geau/data-raw/so_ii_catnat.R
rename to so.ii/data-raw/so_ii_catnat.R
diff --git a/geau/data-raw/so_ii_collectivity.R b/so.ii/data-raw/so_ii_collectivity.R
similarity index 100%
rename from geau/data-raw/so_ii_collectivity.R
rename to so.ii/data-raw/so_ii_collectivity.R
diff --git a/geau/data-raw/so_ii_hydro.R b/so.ii/data-raw/so_ii_hydro.R
similarity index 100%
rename from geau/data-raw/so_ii_hydro.R
rename to so.ii/data-raw/so_ii_hydro.R
diff --git a/geau/data-raw/so_ii_montpellier.R b/so.ii/data-raw/so_ii_montpellier.R
similarity index 100%
rename from geau/data-raw/so_ii_montpellier.R
rename to so.ii/data-raw/so_ii_montpellier.R
diff --git a/geau/data-raw/so_ii_onrn.R b/so.ii/data-raw/so_ii_onrn.R
similarity index 100%
rename from geau/data-raw/so_ii_onrn.R
rename to so.ii/data-raw/so_ii_onrn.R
diff --git a/geau/data-raw/so_ii_osm.R b/so.ii/data-raw/so_ii_osm.R
similarity index 100%
rename from geau/data-raw/so_ii_osm.R
rename to so.ii/data-raw/so_ii_osm.R
diff --git a/geau/data-raw/so_ii_population.R b/so.ii/data-raw/so_ii_population.R
similarity index 100%
rename from geau/data-raw/so_ii_population.R
rename to so.ii/data-raw/so_ii_population.R
diff --git a/geau/data-raw/so_ii_scope.R b/so.ii/data-raw/so_ii_scope.R
similarity index 100%
rename from geau/data-raw/so_ii_scope.R
rename to so.ii/data-raw/so_ii_scope.R
diff --git a/geau/data/clc_color.rda b/so.ii/data/clc_color.rda
similarity index 100%
rename from geau/data/clc_color.rda
rename to so.ii/data/clc_color.rda
diff --git a/geau/data/so_ii_catchment.rda b/so.ii/data/so_ii_catchment.rda
similarity index 100%
rename from geau/data/so_ii_catchment.rda
rename to so.ii/data/so_ii_catchment.rda
diff --git a/geau/data/so_ii_catnat.rda b/so.ii/data/so_ii_catnat.rda
similarity index 100%
rename from geau/data/so_ii_catnat.rda
rename to so.ii/data/so_ii_catnat.rda
diff --git a/geau/data/so_ii_clc.rda b/so.ii/data/so_ii_clc.rda
similarity index 100%
rename from geau/data/so_ii_clc.rda
rename to so.ii/data/so_ii_clc.rda
diff --git a/geau/data/so_ii_collectivity.rda b/so.ii/data/so_ii_collectivity.rda
similarity index 100%
rename from geau/data/so_ii_collectivity.rda
rename to so.ii/data/so_ii_collectivity.rda
diff --git a/geau/data/so_ii_hydro.rda b/so.ii/data/so_ii_hydro.rda
similarity index 100%
rename from geau/data/so_ii_hydro.rda
rename to so.ii/data/so_ii_hydro.rda
diff --git a/geau/data/so_ii_limit.rda b/so.ii/data/so_ii_limit.rda
similarity index 100%
rename from geau/data/so_ii_limit.rda
rename to so.ii/data/so_ii_limit.rda
diff --git a/geau/data/so_ii_montpellier.rda b/so.ii/data/so_ii_montpellier.rda
similarity index 100%
rename from geau/data/so_ii_montpellier.rda
rename to so.ii/data/so_ii_montpellier.rda
diff --git a/geau/data/so_ii_onrn.rda b/so.ii/data/so_ii_onrn.rda
similarity index 100%
rename from geau/data/so_ii_onrn.rda
rename to so.ii/data/so_ii_onrn.rda
diff --git a/geau/data/so_ii_population.rda b/so.ii/data/so_ii_population.rda
similarity index 100%
rename from geau/data/so_ii_population.rda
rename to so.ii/data/so_ii_population.rda
diff --git a/geau/data/so_ii_scope.rda b/so.ii/data/so_ii_scope.rda
similarity index 100%
rename from geau/data/so_ii_scope.rda
rename to so.ii/data/so_ii_scope.rda
diff --git a/geau/inst/extdata/so_ii_osm.tif b/so.ii/inst/extdata/so_ii_osm.tif
similarity index 100%
rename from geau/inst/extdata/so_ii_osm.tif
rename to so.ii/inst/extdata/so_ii_osm.tif
diff --git a/geau/inst/extdata/so_ii_osm.tif.aux.xml b/so.ii/inst/extdata/so_ii_osm.tif.aux.xml
similarity index 100%
rename from geau/inst/extdata/so_ii_osm.tif.aux.xml
rename to so.ii/inst/extdata/so_ii_osm.tif.aux.xml
diff --git a/geau/man/add.inset.Rd b/so.ii/man/add.inset.Rd
similarity index 100%
rename from geau/man/add.inset.Rd
rename to so.ii/man/add.inset.Rd
diff --git a/geau/man/clc_color.Rd b/so.ii/man/clc_color.Rd
similarity index 100%
rename from geau/man/clc_color.Rd
rename to so.ii/man/clc_color.Rd
diff --git a/geau/man/current_version.Rd b/so.ii/man/current_version.Rd
similarity index 100%
rename from geau/man/current_version.Rd
rename to so.ii/man/current_version.Rd
diff --git a/geau/man/estimate_catnat_freq.Rd b/so.ii/man/estimate_catnat_freq.Rd
similarity index 100%
rename from geau/man/estimate_catnat_freq.Rd
rename to so.ii/man/estimate_catnat_freq.Rd
diff --git a/geau/man/format_presence.Rd b/so.ii/man/format_presence.Rd
similarity index 89%
rename from geau/man/format_presence.Rd
rename to so.ii/man/format_presence.Rd
index ca96940..da2f749 100644
--- a/geau/man/format_presence.Rd
+++ b/so.ii/man/format_presence.Rd
@@ -1,5 +1,5 @@
 % Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/presence.R
+% Please edit documentation in R/format_presence.R
 \encoding{UTF-8}
 \name{format_presence}
 \alias{format_presence}
diff --git a/geau/man/kable_units.Rd b/so.ii/man/kable_units.Rd
similarity index 100%
rename from geau/man/kable_units.Rd
rename to so.ii/man/kable_units.Rd
diff --git a/geau/man/map_so_ii.Rd b/so.ii/man/map_so_ii.Rd
similarity index 100%
rename from geau/man/map_so_ii.Rd
rename to so.ii/man/map_so_ii.Rd
diff --git a/so.ii/man/plot_legend.Rd b/so.ii/man/plot_legend.Rd
new file mode 100644
index 0000000..ea96e6e
--- /dev/null
+++ b/so.ii/man/plot_legend.Rd
@@ -0,0 +1,51 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/plot_legend.r
+\encoding{UTF-8}
+\name{plot_legend}
+\alias{plot_legend}
+\title{Plot a legend independently of a map}
+\usage{
+plot_legend(dataset_legend, path = NULL, horiz = TRUE, add = FALSE)
+}
+\arguments{
+\item{dataset_legend}{list of parameters to be passed to legend}
+
+\item{path}{character, the name of the file to save the plot. Graphical
+device is chosen depending on extension. See details.}
+
+\item{horiz}{logical, should the legend be horizontal}
+
+\item{add}{logical, should the legend be added to the current plot}
+}
+\value{
+Nothing useful.
+}
+\description{
+Plot a legend independently of a map
+}
+\details{
+\subsection{path specification}{
+Depending on the extension a device is chosen.
+\itemize{
+\item{\strong{pdf}: grDevices::cairo_pdf}
+\item{\strong{png}: grDevices::png}
+\item{\strong{svg}: grDevices::svg}
+}
+If path is NULL, standard plotting is used. If an extension is not managed,
+an error is raised.
+}
+}
+\examples{
+
+dataset_legend = list(
+ title = "Beatutiful legend",
+ legend = c("red circle", "black square", "blue diamond"),
+ pch = 21:23,
+ pt.bg = c("red", "black", "blue")
+)
+plot_legend(dataset_legend)
+plot_legend(dataset_legend, horiz = FALSE)
+}
+\author{
+Frédéric Grelot
+}
diff --git a/geau/man/so_ii_catchment.Rd b/so.ii/man/so_ii_catchment.Rd
similarity index 100%
rename from geau/man/so_ii_catchment.Rd
rename to so.ii/man/so_ii_catchment.Rd
diff --git a/geau/man/so_ii_catnat.Rd b/so.ii/man/so_ii_catnat.Rd
similarity index 100%
rename from geau/man/so_ii_catnat.Rd
rename to so.ii/man/so_ii_catnat.Rd
diff --git a/geau/man/so_ii_clc.Rd b/so.ii/man/so_ii_clc.Rd
similarity index 100%
rename from geau/man/so_ii_clc.Rd
rename to so.ii/man/so_ii_clc.Rd
diff --git a/geau/man/so_ii_collectivity.Rd b/so.ii/man/so_ii_collectivity.Rd
similarity index 100%
rename from geau/man/so_ii_collectivity.Rd
rename to so.ii/man/so_ii_collectivity.Rd
diff --git a/geau/man/so_ii_hydro.Rd b/so.ii/man/so_ii_hydro.Rd
similarity index 100%
rename from geau/man/so_ii_hydro.Rd
rename to so.ii/man/so_ii_hydro.Rd
diff --git a/geau/man/so_ii_limit.Rd b/so.ii/man/so_ii_limit.Rd
similarity index 100%
rename from geau/man/so_ii_limit.Rd
rename to so.ii/man/so_ii_limit.Rd
diff --git a/geau/man/so_ii_montpellier.Rd b/so.ii/man/so_ii_montpellier.Rd
similarity index 100%
rename from geau/man/so_ii_montpellier.Rd
rename to so.ii/man/so_ii_montpellier.Rd
diff --git a/geau/man/so_ii_onrn.Rd b/so.ii/man/so_ii_onrn.Rd
similarity index 100%
rename from geau/man/so_ii_onrn.Rd
rename to so.ii/man/so_ii_onrn.Rd
diff --git a/geau/man/so_ii_population.Rd b/so.ii/man/so_ii_population.Rd
similarity index 100%
rename from geau/man/so_ii_population.Rd
rename to so.ii/man/so_ii_population.Rd
diff --git a/geau/man/so_ii_scope.Rd b/so.ii/man/so_ii_scope.Rd
similarity index 100%
rename from geau/man/so_ii_scope.Rd
rename to so.ii/man/so_ii_scope.Rd
-- 
GitLab