Learn R Programming

tidyterra (version 0.1.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,
  ...
)

Arguments

object

A SpatRaster object.

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

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().

Value

A ggplot2 layer

Details

Implementation of ggplot2::autoplot().

See Also

ggplot2::autoplot()

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

Examples

Run this code
# NOT RUN {
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