Returns a cowplot object for a global map plot.

plot_map4(
  obj,
  varnam = NA,
  maxval = NA,
  breaks = NA,
  lonmin = -180,
  lonmax = 180,
  latmin = -90,
  latmax = 90,
  nbin = 10,
  legend_title = waiver(),
  legend_direction = "vertical",
  colorscale = viridis::viridis,
  color_ocean = "azure3",
  invert = -1,
  do_reproj = FALSE,
  hillshade = FALSE,
  rivers = FALSE,
  lakes = FALSE,
  coast = TRUE,
  ocean = FALSE,
  countries = FALSE,
  dir_ne = "~/data/naturalearth/",
  states = FALSE,
  scale = 110,
  make_discrete = TRUE,
  use_geom_raster = TRUE,
  is_boolean = FALSE,
  plot_title = waiver(),
  plot_subtitle = waiver(),
  combine = TRUE,
  ...
)

Arguments

obj

An object, either a SpatRaster (returned from a terra::rast() function call), or a list returned from a GECOr::read_nc_onefile() function call.

varnam

A charachter string specifying the variable name. Optional and used only if obj is a SpatRaster with multiple variables. If obj is a rbeni-nc object (returned by read_nc_onefile()), varnam must be provided (a character string specifying the variable name in obj$vars[[varnam]]).

maxval

A numeric value specifying the maximum value for which the color key is to be extended. Defaults to NA (the 99% quantile of values is used).

breaks

A numeric vector specifying the breaks for the color scale. Defaults to NA, i.e. breaks are determined automatically based on nbin and maxval.

lonmin

Left edge (longitude, in degrees), defaults to -180.

lonmax

Right edge (longitude, in degrees), defaults to 180.

latmin

Lower edge (latitude, in degrees), defaults to -90.

latmax

Upper edge (latitude, in degrees), defaults to 90.

nbin

An integer specifying the number of bins used for the color key.

legend_title

A character string specifying the legend title (annotation above the color key)

legend_direction

Either "vertical" (default) or "horizontal".

colorscale

Either function that returns a set of colors or a vector of color names from which to interpolate. Defaults to virids::viridis.

color_ocean

A color specifyier for the fill color of the ocean layer. Defaults to "azure".

invert

One of 1 or -1, specifying the direction of the color scale. Defaults to -1.

do_reproj

A boolean specifying whether to re-project the map to Robin projection

hillshade

A logical specifying whether a hillshade layer should be added. Defaults to FALSE.

rivers

A logical specifying whether to display rivers (the ne_50m_rivers_lake_centerlines layer from NaturalEarth.). Defaults to FALSE.

lakes

A logical specifying whether to display rivers (the ne_50m_lakes layer from NaturalEarth). Defaults to FALSE.

coast

A logical specifying whether to display coastlines (the ne_50m_coastline layer from NaturalEarth). Defaults to TRUE.

ocean

A logical specifying whether to display the ocean layer from NaturalEarth). Defaults to FALSE.

countries

A logical specifying whether to display country borders (the ne_50m_admin_0_countries layer from NaturalEarth). Defaults to FALSE.

dir_ne

A character string specifying where to download Naturalearth layers. Once downloaded, they can be quickly loaded. Defaults to "~/data/naturalearth/".

states

A logical specifying whether to display sub-country administrative borders (e.g. US states) (the ne_50m_admin_1_states_provinces layer from NaturalEarth). Defaults to FALSE.

scale

An integer specifying the resolutuion of NaturalEarth layers (coast, rivers, lakes). One of 110, 50, 10. Defaults to 110 (coarsest resolution). NaturalEarth layers for 110, 50, 10 m are used for low, medium, and high resolution (scale) layers, respectively. Defaults to "small".

make_discrete

A logical scpecifying whether data layer is to be made discrete for plotting with colors of discrete bins. Defaults to TRUE.

use_geom_raster

A logical specifying whether to use the function geom_raster() for plotting the raster layer. Defaults to TRUE. If FALSE, geom_tile() is used. The latter can yield nicer results when data is sparse.

is_boolean

A logical specifying whether the raster contains boolean values (either TRUE or FALSE). Defaults to FALSE.

plot_title

A character string specifying the plot title

plot_subtitle

A character string specifying the plot subtitle

combine

A boolean specifying whether the map and the colorscale should be combined using cowplot. Defaults to TRUE. If FALSE, a list of elements are retruned, where elements are the ggplot2 plot object and the coloscale object returned by the call to plot_discrete_cbar.

Value

A ggplot object for a global map plot.