Learn R Programming

mapSpain (version 0.6.1)

layer_spatraster: Spatial ggplot2 layer for SpatRaster objects

Description

[Experimental]

This is a wrapper of ggspatial::layer_spatial.Raster() that works with SpatRaster objects.

This function is likely to be deprecated in the future when ggspatial (or any other package) provides native support to SpatRaster on ggplot. See also https://github.com/paleolimbot/ggspatial/issues/91

Other packages that supports natively SpatRaster:

Usage

layer_spatraster(data, ...)

Arguments

data

A SpatRaster object created with terra::rast().

...

Arguments passed on to ggspatial::layer_spatial

mapping

A mapping, created using aes.

Value

A ggplot2 layer

Details

This function requires both ggspatial and raster packages.

You can install both running install.packages("ggspatial", dependencies = TRUE)

See Also

ggspatial::layer_spatial.Raster(), raster::stack().

Other imagery utilities: addProviderEspTiles(), esp_getTiles(), leaflet.providersESP.df

Examples

Run this code
# NOT RUN {
# Get a SpatRaster

x <- esp_get_ccaa("Galicia")

tile <- esp_getTiles(x, "IDErioja")

class(tile)

library(ggplot2)

ggplot(x) +
  layer_spatraster(tile) +
  geom_sf(color = "yellow", fill = NA) +
  theme_minimal()
# }

Run the code above in your browser using DataLab