diff --git a/geau/DESCRIPTION b/geau/DESCRIPTION index e6a397ddec12c2042a2c3e7c7cba64f63b118a86..adf2a63b3a2494ae7e41e8fa30801a0eef4999ae 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.8.0 +Version: 1.0.9.0 Authors@R: c( person(given = "Frédéric", diff --git a/geau/R/map_so_ii.r b/geau/R/map_so_ii.r index 14d4ceb4c92d9f9592f34dcbfc662685d4bd247d..f2c4f4df0e289c173e9f0a36efedd9321119273f 100644 --- a/geau/R/map_so_ii.r +++ b/geau/R/map_so_ii.r @@ -33,11 +33,11 @@ #' @param dataset sf objectf, data to be plotted #' @param dataset_legend list of parameters to be passed to legend #' @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 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) #' #' @return Nothing useful. @@ -58,11 +58,11 @@ map_so_ii = function( dataset, dataset_legend = NULL, theme = c("none", "collectivity", "catchment", "catnat", "clc", "hydro", "onrn", "population"), + theme_legend = FALSE, + detail, + year, bar = TRUE, path = NULL, - legend_theme = FALSE, - year, - detail, ... ) { theme = match.arg(theme) @@ -81,23 +81,26 @@ map_so_ii = function( graphics::par(mai = c(.65, .60, .50, .15)) plot(geau::so_ii_limit, axes = TRUE) - ## Plot theme if any + ## Plot theme if any, return theme_legend theme_legend = switch( EXPR = theme, - "catchment" = map_theme_catchment(detail, legend_theme), - "catnat" = map_theme_catnat(detail, year, legend_theme), - "clc" = map_theme_clc(legend_theme), - "collectivity" = map_theme_collectivity(detail, legend_theme), - "hydro" = map_theme_hydro(detail, legend_theme), - "onrn" = map_theme_onrn(detail, legend_theme), - "population" = map_theme_population(year, legend_theme), + "catchment" = map_theme_catchment(detail, theme_legend), + "catnat" = map_theme_catnat(detail, year, theme_legend), + "clc" = map_theme_clc(theme_legend), + "collectivity" = map_theme_collectivity(detail, theme_legend), + "hydro" = map_theme_hydro(detail, theme_legend), + "onrn" = map_theme_onrn(detail, theme_legend), + "population" = map_theme_population(year, theme_legend), + NULL ) - + ## Plot dataset if any if (!missing(dataset)) plot(dataset[["geometry"]], add = TRUE, ...) + ## Make so_ii_limit visible plot(geau::so_ii_limit, lwd = 2, add = TRUE) + ## Plot bar if (bar == TRUE) { terra::sbar( 10, c(3.55, 43.47), @@ -108,6 +111,7 @@ map_so_ii = function( ) } + ## Plotdataset_legend if any if (!is.null(dataset_legend)) { dataset_legend = c( x = "bottomright", @@ -118,7 +122,8 @@ map_so_ii = function( 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"]])) { text_legend = theme_legend[["legend"]] theme_legend[["legend"]] = rep("", length(text_legend)) diff --git a/geau/man/map_so_ii.Rd b/geau/man/map_so_ii.Rd index 592e5ef10b847d2a42e02585496698d7fc4198be..a118b15c1603bdfb23da7bb3134b42e3e4a3bec7 100644 --- a/geau/man/map_so_ii.Rd +++ b/geau/man/map_so_ii.Rd @@ -10,11 +10,11 @@ map_so_ii( dataset_legend = NULL, theme = c("none", "collectivity", "catchment", "catnat", "clc", "hydro", "onrn", "population"), + theme_legend = FALSE, + detail, + year, bar = TRUE, path = NULL, - legend_theme = FALSE, - year, - detail, ... ) } @@ -25,15 +25,15 @@ map_so_ii( \item{theme}{character, choice for the theme (if any)} -\item{bar}{logical, should a bar be plotted for the dataset} - -\item{path}{character, the name of the file to save the plot} +\item{theme_legend}{logical, should a legend be plotted for the theme} -\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{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)} } diff --git a/map_so_ii.rmd b/map_so_ii.rmd index 506eae92b87fd91e1eb37e033957441e3a8b1dc8..858fa58c44eeaa051269d7edb1216e3d8963a92d 100644 --- a/map_so_ii.rmd +++ b/map_so_ii.rmd @@ -5,25 +5,25 @@ map_so_ii(theme = "collectivity") map_so_ii(theme = "collectivity", detail = "syndicate") map_so_ii(theme = "collectivity", detail = "syble") 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 = "population", legend_theme = TRUE) -map_so_ii(theme = "population", year = "2006", legend_theme = TRUE) +map_so_ii(theme = "population", theme_legend = TRUE) +map_so_ii(theme = "population", year = "2006", theme_legend = TRUE) map_so_ii(theme = "catnat", year = 2019) map_so_ii(theme = "hydro") map_so_ii(theme = "hydro", detail = 2) map_so_ii(theme = "hydro", detail = "river") map_so_ii(theme = "catchment") -map_so_ii(theme = "catchment", detail = 2, legend_theme = TRUE) -map_so_ii(theme = "catchment", detail = 3, legend_theme = TRUE) -map_so_ii(theme = "onrn", detail = "n_catnat", legend_theme = TRUE) -map_so_ii(theme = "onrn", detail = "freq_sin", legend_theme = TRUE) -map_so_ii(theme = "onrn", detail = "cost", legend_theme = TRUE) -map_so_ii(theme = "onrn", detail = "cost_hab", legend_theme = TRUE) -map_so_ii(theme = "onrn", detail = "cost_mean", legend_theme = TRUE) -map_so_ii(theme = "onrn", detail = "ratio", legend_theme = TRUE) -map_so_ii(theme = "onrn", detail = "balance", legend_theme = TRUE) -map_so_ii(theme = "onrn", detail = "ppri_year", legend_theme = TRUE) +map_so_ii(theme = "catchment", detail = 2, theme_legend = TRUE) +map_so_ii(theme = "catchment", detail = 3, theme_legend = TRUE) +map_so_ii(theme = "onrn", detail = "n_catnat", theme_legend = TRUE) +map_so_ii(theme = "onrn", detail = "freq_sin", theme_legend = TRUE) +map_so_ii(theme = "onrn", detail = "cost", theme_legend = TRUE) +map_so_ii(theme = "onrn", detail = "cost_hab", theme_legend = TRUE) +map_so_ii(theme = "onrn", detail = "cost_mean", theme_legend = TRUE) +map_so_ii(theme = "onrn", detail = "ratio", theme_legend = TRUE) +map_so_ii(theme = "onrn", detail = "balance", theme_legend = TRUE) +map_so_ii(theme = "onrn", detail = "ppri_year", theme_legend = TRUE) # Can only work if data-common is a symbolic link @@ -51,11 +51,11 @@ dataset_legend = list( 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 = "catnat", year = 2020, legend_theme = 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 = "population", 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, theme_legend = 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", 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-catnat.pdf", bg = bg, pch = pch, theme = "catnat", year = 2020, legend_theme = TRUE) -map_so_ii(dataset, dataset_legend, path = "rex-population.pdf", bg = bg, pch = pch, theme = "population", legend_theme = TRUE) \ No newline at end of file +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, theme_legend = 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