helper function to plot_rast_gg and plot_vect which adds and customizes the scale_fill palette based on characteristics of the plot (e.g., categorical or continuous variable), selected palette and options concerning treatment of outliers.

add_scale_fill(plot, palette, scale_transform, title, na.color, zlims,
  leg_breaks, leg_labels, leg_colors, leg_type, outliers_style, direction,
  ...)

Arguments

plot

gg object to which the fill scale has to be added.

palette

data.frame (1) Line of the d.f. created by fillpals corresponding to the desired palette.

scale_transform

character optional transformation to be applied on values of continuous fill variables (e.g., "log"), Default: NULL

title

character Name to be used as title in the palette legend.

na.color

character, color to be used to plot NA values, Default: 'transparent'.

zlims

numeric array [2] limits governing the range of values to be plotted (e.g., c(0.2,0.4)), Default: NULL

leg_breaks

numeric (n_leg_labels) Values in the scale at which leg_labels must be placed (if rast_type != "categorical"). The number of breaks must be equal to the number of labels specified by "leg_labels". If this is not TRUE, leg_breaks and leg_labels are reset to waiver() (TBD) Default: NULL (the default ggplot2 labels = waiver() is used)

leg_labels

character (n_leg_breaks) labels to be used for the legend

  • If rast_type == "categorical", the number of labels must correspond to the number of unique values of the raster to be plotted. If NULL or not valid, the legend will use the unique raster values in the legend (see examples)

  • If rast_type == "continuous" the number of labels must be equal to the number of breaks specified by "leg_breaks". If this is not TRUE, leg_breaks and leg_labels are reset to waiver() (TBD), Default: NULL (the default ggplot2 labels = waiver() is used)

leg_colors

character (n_leg_labels) Colors to be assigned to the different values of fill_var if palette_name == "manual". The number of colors must be equal to the number of unique values of fill_var, otherwise an error will be issued. Colors can be specified as R color names (e.g., leg_colors = c("red", "blue"), HEX values (e.g., leg_colours = c(#8F2525, #41AB96), or a mix of the two. Note that the argument is mandatory if palette_name == "manual", and ignored on all other palettes, Default: NULL

leg_type

character ["continuous", "discrete"] type of legend to be used on continuous variables. If "continuous" , a colourbar is used. If "discrete", a discretized version is used (see examples).#'

outliers_style

character ["censor" | "to_minmax"] specifies how the values outside of the zlims range will be plotted.

  • If == "censor", they are plotted using the colors(s) specified in outliers_color

  • If == "to_minmax", outliers are forced to the colors used for the maximum and minimum values specified in zlims (using scales::squish), Default: censor.

direction

character [0 | 1] direction of the color legend. Change this to invert the color gradient, Default: 1

...

any other parameter to be passed to ggplot::scale_fill_brewer or ggplot::scale_fill_hue

Value

The function is called for its side effects.