This is a helper function to plot a map of an environmental raster.
The raster is plotted as is, with its given coordinate reference system.
The function can provide a background map if the background argument is
toggled.
Arguments
- x
a
SpatRasterobject (packageterra). A raster of one single layer- background
a
logical. IfTRUEadds a layer of country boundaries from Natural Earth.- ...
other parameters passed to
ggplot2::theme()
Examples
library(ggplot2)
## Load raster ----
tavg <- system.file("extdata", "annual_mean_temp.tif", package = "funbiogeo")
tavg <- terra::rast(tavg)
## Default map ----
fb_map_raster(tavg)
## Map with a background ----
fb_map_raster(tavg, background = TRUE)
## Map with custom theme ----
fb_map_raster(tavg, legend.position = "bottom")
## Advanced customization ----
my_map <- fb_map_raster(tavg) +
scale_fill_distiller("Temperature", palette = "Spectral") +
theme(legend.position = "bottom") +
ggtitle("Mean annual temperature in Western Europe")
my_map
## Map w/o annotation ----
fb_map_raster(tavg) +
theme_void() +
theme(legend.position = "none")
