Passer au contenu

Creates a background layer for plotting, supporting both continuous and discrete data.

Utilisation

elsar_plot_background(
  plot_type = "ggplot",
  background_dat = NULL,
  data_type = c("continuous", "discrete"),
  rescale_background = TRUE,
  increase_extend = 0.05,
  main_data = NULL,
  background_alpha = 0.2,
  color_map = "viridis",
  custom_palette = NULL,
  categorical = FALSE,
  number_categories = 10,
  data_layer = NULL
)

elsar_plot_background_c(
  plot_type = "ggplot",
  background_dat = NULL,
  rescale_background = TRUE,
  increase_extend = 0.05,
  main_data = NULL,
  background_alpha = 0.2,
  color_map = "viridis",
  custom_palette = NULL
)

elsar_plot_background_d(
  plot_type = "ggplot",
  background_dat = NULL,
  rescale_background = TRUE,
  increase_extend = 0.05,
  main_data = NULL,
  background_alpha = 0.2,
  color_map = "viridis",
  custom_palette = NULL,
  categorical = FALSE,
  number_categories = 10,
  data_layer = NULL
)

Arguments

plot_type

A character denoting whether "ggplot" or "tmap" is being used. Needs to match the main plot.

background_dat

A SpatRaster file that contains the data to be used as a background.

data_type

Character. Either "continuous" (default) or "discrete" to specify how data should be displayed.

rescale_background

Logical. If TRUE, rescales the SpatRaster to values between 0-1.

increase_extend

A numerical value that allows to extend the background beyond the extent of raster_in. If extend_background <= 1, the lat and lon extend will be extended by the ratio provided (e.g. 0.05 will extend it by 5%). If extend_background > 1 all sides will be extended by the absolute value provided.

main_data

A SpatRaster file that contains the data that will be the main part of the main plot.

background_alpha

A value (0-1) for the opacity of the background layer. Default is 0.2.

color_map

The name of the viridis palette to be used. Default is "viridis".

custom_palette

An optional custom palette for plotting. Default uses the viridis package.

categorical

Logical. Only used when data_type = "discrete". If TRUE, data is already categorical.

number_categories

Integer. Only used when data_type = "discrete". Number of categories to split continuous data into.

data_layer

Character. Only used when data_type = "discrete". The data layer name for categorization.

Valeur de retour

A list of a ggplot or tmap object and a data frame with the background data.

Exemples

if (FALSE) { # \dontrun{
boundary_proj <- make_boundary(
  boundary_in = boundary_dat,
  iso3 = "NPL",
  iso3_column = "iso3cd"
)

pus <- make_planning_units(
  boundary_proj = boundary_proj,
  iso3 = "NPL",
  pu_size = NULL,
  pu_threshold = 8.5e5,
  limit_to_mainland = FALSE
)
wad_dat <- get_wad_data()

wadOut <- make_normalised_raster(
  raster_in = wad_dat,
  pus = pus,
  iso3 = "NPL"
)

# Continuous background
(background_plot <- elsar_plot_background(
  background_dat = wad_dat,
  main_data = wadOut
))

# Discrete background
(background_plot_d <- elsar_plot_background(
  background_dat = wad_dat,
  main_data = wadOut,
  data_type = "discrete",
  number_categories = 10,
  data_layer = "wad_final_cog"
))
} # }