Commit 02a95449 authored by Grelot Frederic's avatar Grelot Frederic :swimmer_tone5:
Browse files

geau version 1.0.9.0

0 errors :heavy_check_mark: | 0 warnings :heavy_check_mark: | 0 notes :heavy_check_mark:

- map_so_ii
	- ajout des commentaires
	- réorganisation des paramètres, theme_legend au lieu de legend_theme pour cohérence
- exemples dans map_so_ii
	- adaptation avec nouveaux paramètres
Showing with 50 additions and 45 deletions
+50 -45
Package: geau Package: geau
Title: Utilities very useful to share within geau-inondation team Title: Utilities very useful to share within geau-inondation team
Version: 1.0.8.0 Version: 1.0.9.0
Authors@R: Authors@R:
c( c(
person(given = "Frédéric", person(given = "Frédéric",
......
...@@ -33,11 +33,11 @@ ...@@ -33,11 +33,11 @@
#' @param dataset sf objectf, data to be plotted #' @param dataset sf objectf, data to be plotted
#' @param dataset_legend list of parameters to be passed to legend #' @param dataset_legend list of parameters to be passed to legend
#' @param theme character, choice for the theme (if any) #' @param theme character, choice for the theme (if any)
#' @param theme_legend logical, should a legend be plotted for the theme
#' @param detail character, detail for theme, depends on theme. See details.
#' @param year character, the year chosen for some themes (catnat, population)
#' @param bar logical, should a bar be plotted for the dataset #' @param bar logical, should a bar be plotted for the dataset
#' @param path character, the name of the file to save the plot #' @param path character, the name of the file to save the plot
#' @param legend_theme logical, should a legend be plotted for the theme
#' @param year character, the year chosen for some themes (catnat, population)
#' @param detail character, detail for theme, depends on theme. See details.
#' @param ... some parameters that will be used by plot (from sf) #' @param ... some parameters that will be used by plot (from sf)
#' #'
#' @return Nothing useful. #' @return Nothing useful.
...@@ -58,11 +58,11 @@ map_so_ii = function( ...@@ -58,11 +58,11 @@ map_so_ii = function(
dataset, dataset,
dataset_legend = NULL, dataset_legend = NULL,
theme = c("none", "collectivity", "catchment", "catnat", "clc", "hydro", "onrn", "population"), theme = c("none", "collectivity", "catchment", "catnat", "clc", "hydro", "onrn", "population"),
theme_legend = FALSE,
detail,
year,
bar = TRUE, bar = TRUE,
path = NULL, path = NULL,
legend_theme = FALSE,
year,
detail,
... ...
) { ) {
theme = match.arg(theme) theme = match.arg(theme)
...@@ -81,23 +81,26 @@ map_so_ii = function( ...@@ -81,23 +81,26 @@ map_so_ii = function(
graphics::par(mai = c(.65, .60, .50, .15)) graphics::par(mai = c(.65, .60, .50, .15))
plot(geau::so_ii_limit, axes = TRUE) plot(geau::so_ii_limit, axes = TRUE)
## Plot theme if any ## Plot theme if any, return theme_legend
theme_legend = switch( theme_legend = switch(
EXPR = theme, EXPR = theme,
"catchment" = map_theme_catchment(detail, legend_theme), "catchment" = map_theme_catchment(detail, theme_legend),
"catnat" = map_theme_catnat(detail, year, legend_theme), "catnat" = map_theme_catnat(detail, year, theme_legend),
"clc" = map_theme_clc(legend_theme), "clc" = map_theme_clc(theme_legend),
"collectivity" = map_theme_collectivity(detail, legend_theme), "collectivity" = map_theme_collectivity(detail, theme_legend),
"hydro" = map_theme_hydro(detail, legend_theme), "hydro" = map_theme_hydro(detail, theme_legend),
"onrn" = map_theme_onrn(detail, legend_theme), "onrn" = map_theme_onrn(detail, theme_legend),
"population" = map_theme_population(year, legend_theme), "population" = map_theme_population(year, theme_legend),
NULL
) )
## Plot dataset if any
if (!missing(dataset)) plot(dataset[["geometry"]], add = TRUE, ...) if (!missing(dataset)) plot(dataset[["geometry"]], add = TRUE, ...)
## Make so_ii_limit visible
plot(geau::so_ii_limit, lwd = 2, add = TRUE) plot(geau::so_ii_limit, lwd = 2, add = TRUE)
## Plot bar
if (bar == TRUE) { if (bar == TRUE) {
terra::sbar( terra::sbar(
10, c(3.55, 43.47), 10, c(3.55, 43.47),
...@@ -108,6 +111,7 @@ map_so_ii = function( ...@@ -108,6 +111,7 @@ map_so_ii = function(
) )
} }
## Plotdataset_legend if any
if (!is.null(dataset_legend)) { if (!is.null(dataset_legend)) {
dataset_legend = c( dataset_legend = c(
x = "bottomright", x = "bottomright",
...@@ -118,7 +122,8 @@ map_so_ii = function( ...@@ -118,7 +122,8 @@ map_so_ii = function(
do.call(graphics::legend, dataset_legend) do.call(graphics::legend, dataset_legend)
} }
if (legend_theme == TRUE && exists("theme_legend", inherits = FALSE)) { ## Plot theme_legend if any
if (!is.null(theme_legend)) {
if (!is.null(theme_legend[["text.width"]])) { if (!is.null(theme_legend[["text.width"]])) {
text_legend = theme_legend[["legend"]] text_legend = theme_legend[["legend"]]
theme_legend[["legend"]] = rep("", length(text_legend)) theme_legend[["legend"]] = rep("", length(text_legend))
......
...@@ -10,11 +10,11 @@ map_so_ii( ...@@ -10,11 +10,11 @@ map_so_ii(
dataset_legend = NULL, dataset_legend = NULL,
theme = c("none", "collectivity", "catchment", "catnat", "clc", "hydro", "onrn", theme = c("none", "collectivity", "catchment", "catnat", "clc", "hydro", "onrn",
"population"), "population"),
theme_legend = FALSE,
detail,
year,
bar = TRUE, bar = TRUE,
path = NULL, path = NULL,
legend_theme = FALSE,
year,
detail,
... ...
) )
} }
...@@ -25,15 +25,15 @@ map_so_ii( ...@@ -25,15 +25,15 @@ map_so_ii(
\item{theme}{character, choice for the theme (if any)} \item{theme}{character, choice for the theme (if any)}
\item{bar}{logical, should a bar be plotted for the dataset} \item{theme_legend}{logical, should a legend be plotted for the theme}
\item{path}{character, the name of the file to save the plot}
\item{legend_theme}{logical, should a legend be plotted for the theme} \item{detail}{character, detail for theme, depends on theme. See details.}
\item{year}{character, the year chosen for some themes (catnat, population)} \item{year}{character, the year chosen for some themes (catnat, population)}
\item{detail}{character, detail for theme, depends on theme. See details.} \item{bar}{logical, should a bar be plotted for the dataset}
\item{path}{character, the name of the file to save the plot}
\item{...}{some parameters that will be used by plot (from sf)} \item{...}{some parameters that will be used by plot (from sf)}
} }
......
...@@ -5,25 +5,25 @@ map_so_ii(theme = "collectivity") ...@@ -5,25 +5,25 @@ map_so_ii(theme = "collectivity")
map_so_ii(theme = "collectivity", detail = "syndicate") map_so_ii(theme = "collectivity", detail = "syndicate")
map_so_ii(theme = "collectivity", detail = "syble") map_so_ii(theme = "collectivity", detail = "syble")
map_so_ii(theme = "collectivity", detail = "symbo") map_so_ii(theme = "collectivity", detail = "symbo")
map_so_ii(theme = "collectivity", detail = "epci", legend_theme = TRUE) map_so_ii(theme = "collectivity", detail = "epci", theme_legend = TRUE)
map_so_ii(theme = "clc") map_so_ii(theme = "clc")
map_so_ii(theme = "population", legend_theme = TRUE) map_so_ii(theme = "population", theme_legend = TRUE)
map_so_ii(theme = "population", year = "2006", legend_theme = TRUE) map_so_ii(theme = "population", year = "2006", theme_legend = TRUE)
map_so_ii(theme = "catnat", year = 2019) map_so_ii(theme = "catnat", year = 2019)
map_so_ii(theme = "hydro") map_so_ii(theme = "hydro")
map_so_ii(theme = "hydro", detail = 2) map_so_ii(theme = "hydro", detail = 2)
map_so_ii(theme = "hydro", detail = "river") map_so_ii(theme = "hydro", detail = "river")
map_so_ii(theme = "catchment") map_so_ii(theme = "catchment")
map_so_ii(theme = "catchment", detail = 2, legend_theme = TRUE) map_so_ii(theme = "catchment", detail = 2, theme_legend = TRUE)
map_so_ii(theme = "catchment", detail = 3, legend_theme = TRUE) map_so_ii(theme = "catchment", detail = 3, theme_legend = TRUE)
map_so_ii(theme = "onrn", detail = "n_catnat", legend_theme = TRUE) map_so_ii(theme = "onrn", detail = "n_catnat", theme_legend = TRUE)
map_so_ii(theme = "onrn", detail = "freq_sin", legend_theme = TRUE) map_so_ii(theme = "onrn", detail = "freq_sin", theme_legend = TRUE)
map_so_ii(theme = "onrn", detail = "cost", legend_theme = TRUE) map_so_ii(theme = "onrn", detail = "cost", theme_legend = TRUE)
map_so_ii(theme = "onrn", detail = "cost_hab", legend_theme = TRUE) map_so_ii(theme = "onrn", detail = "cost_hab", theme_legend = TRUE)
map_so_ii(theme = "onrn", detail = "cost_mean", legend_theme = TRUE) map_so_ii(theme = "onrn", detail = "cost_mean", theme_legend = TRUE)
map_so_ii(theme = "onrn", detail = "ratio", legend_theme = TRUE) map_so_ii(theme = "onrn", detail = "ratio", theme_legend = TRUE)
map_so_ii(theme = "onrn", detail = "balance", legend_theme = TRUE) map_so_ii(theme = "onrn", detail = "balance", theme_legend = TRUE)
map_so_ii(theme = "onrn", detail = "ppri_year", legend_theme = TRUE) map_so_ii(theme = "onrn", detail = "ppri_year", theme_legend = TRUE)
# Can only work if data-common is a symbolic link # Can only work if data-common is a symbolic link
...@@ -51,11 +51,11 @@ dataset_legend = list( ...@@ -51,11 +51,11 @@ dataset_legend = list(
pt.cex = cex pt.cex = cex
) )
map_so_ii(dataset, dataset_legend, bg = bg, pch = pch, theme = "clc", legend_theme = TRUE) map_so_ii(dataset, dataset_legend, bg = bg, pch = pch, theme = "clc", theme_legend = TRUE)
map_so_ii(dataset, dataset_legend, bg = bg, pch = pch, theme = "catnat", year = 2020, legend_theme = TRUE) map_so_ii(dataset, dataset_legend, bg = bg, pch = pch, theme = "catnat", year = 2020, theme_legend = TRUE)
map_so_ii(dataset, dataset_legend, bg = bg, pch = pch, theme = "catnat", year = 2020, hazard = "nappe", legend_theme = TRUE) map_so_ii(dataset, dataset_legend, bg = bg, pch = pch, theme = "catnat", year = 2020, hazard = "nappe", theme_legend = TRUE)
map_so_ii(dataset, dataset_legend, bg = bg, pch = pch, theme = "population", legend_theme = TRUE) map_so_ii(dataset, dataset_legend, bg = bg, pch = pch, theme = "population", theme_legend = TRUE)
map_so_ii(dataset, dataset_legend, path = "rex-clc.pdf", bg = bg, pch = pch, theme = "clc", year = 2020, legend_theme = TRUE) map_so_ii(dataset, dataset_legend, path = "rex-clc.pdf", bg = bg, pch = pch, theme = "clc", year = 2020, theme_legend = TRUE)
map_so_ii(dataset, dataset_legend, path = "rex-catnat.pdf", bg = bg, pch = pch, theme = "catnat", year = 2020, legend_theme = TRUE) map_so_ii(dataset, dataset_legend, path = "rex-catnat.pdf", bg = bg, pch = pch, theme = "catnat", year = 2020, theme_legend = TRUE)
map_so_ii(dataset, dataset_legend, path = "rex-population.pdf", bg = bg, pch = pch, theme = "population", legend_theme = TRUE) map_so_ii(dataset, dataset_legend, path = "rex-population.pdf", bg = bg, pch = pch, theme = "population", theme_legend = TRUE)
\ No newline at end of file \ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment