Learn R Programming

tidyterra (version 0.3.0)

autoplot: Create a complete ggplot for SpatRasters

Description

autoplot() uses ggplot2 to draw plots as the ones produced by terra::plot()/terra::plotRGB() in a single command.

Usage

# S3 method for SpatRaster
autoplot(
  object,
  mapping = aes(),
  rgb = FALSE,
  facets = TRUE,
  nrow = NULL,
  ncol = 2,
  ...
)

Value

A ggplot2 layer

Arguments

object

A SpatRaster object.

mapping

Set of aesthetic mappings created by ggplot2::aes() or ggplot2::aes_(). See Aesthetics specially in the use of fill aesthetic.

rgb

Logical. Should be plotted as a RGB image?

facets

Logical. Should facets be displayed?

nrow, ncol

Number of rows and columns on the facet.

...

other arguments passed to geom_spatraster() or geom_spatraster_rgb().

Details

Implementation of ggplot2::autoplot().

See Also

ggplot2::autoplot()

Other ggplot2 utils: geom_spat_contour, geom_spatraster_rgb(), geom_spatraster(), ggspatvector

Examples

Run this code
# \donttest{

file_path <- system.file("extdata/cyl_temp.tif", package = "tidyterra")

library(terra)
temp <- rast(file_path)

library(ggplot2)
autoplot(temp)


# With a tile

system.file("extdata/cyl_tile.tif", package = "tidyterra") %>%
  rast() %>%
  autoplot(rgb = TRUE)
# }

Run the code above in your browser using DataLab