[Questioning] This general purpose function can be used to generate a global map for a single variable. It has few defaults but the data supplied must contain a country variable for linking to mapping data. This function requires the installation of the rnaturalearth package. Status of this function is currently questioning as it is uncertain if it is in use. Future releases may depreciate it.

global_map(
  data = NULL,
  variable = NULL,
  variable_label = NULL,
  trans = "identity",
  fill_labels = NULL,
  scale_fill = NULL,
  ...
)

Arguments

data

Dataframe containing variables to be mapped. Must contain a country variable.

variable

A character string indicating the variable to map data for. This must be supplied.

variable_label

A character string indicating the variable label to use. If not supplied then the underlying variable name is used.

trans

A character string specifying the transform to use on the specified metric. Defaults to no transform ("identity"). Other options include log scaling ("log") and log base 10 scaling ("log10"). For a complete list of options see ggplot2::continous_scale.

fill_labels

A function to use to allocate legend labels. An example (used below) is scales::percent, which can be used for percentage data.

scale_fill

Function to use for scaling the fill. Defaults to a custom ggplot2::scale_fill_manual, which expects the possible values to be "Increasing", "Likely increasing", "Likely decreasing", "Decreasing" or "Stable".

...

Additional arguments passed to the scale_fill function

Value

A ggplot2 object containing a global map.

Examples

# \donttest{
if (requireNamespace("rnaturalearth") & requireNamespace("scales")) {
  # Example 1 - categorical data
  # If values are "Increasing", "Likely increasing" etc (see ?EpiNow2::theme_map),
  # then the default fill scale works
  eg_data <- data.table::data.table(
    variable = c(
      "Increasing",
      "Decreasing",
      "Stable",
      "Likely decreasing",
      "Likely increasing"
    ),
    country = c(
      "France",
      "Germany",
      "United Kingdom",
      "Spain",
      "Australia"
    )
  )
  # make variable a factor so the ordering is sensible in the legend
  eg_data$variable <- factor(eg_data$variable, levels = c(
    "Decreasing", "Likely decreasing",
    "Stable", "Likely increasing",
    "Increasing"
  ))
  global_map(eg_data, variable = "variable", variable_label = "Direction\nof change")


  # Example 2 - numeric data
  # numeric data requires scale_fill and a global viridis_palette specified
  eg_data$second_variable <- runif(nrow(eg_data))
  viridis_palette <- "A"
  global_map(eg_data, variable = "second_variable", scale_fill = scale_fill_viridis_c)
}
#> The rnaturalearthdata package needs to be installed.
#> Installing the rnaturalearthdata package.
#> Installing package into ‘/Users/runner/work/_temp/Library’
#> (as ‘lib’ is unspecified)
#> Error in value[[3L]](cond): Failed to install the rnaturalearthdata package.
#>  Please try installing the package for yourself using the following command: 
#>  install.packages("rnaturalearthdata")
# }