autoplot.Spat {tidyterra} | R Documentation |
Create a complete ggplot for Spat*
objects
Description
autoplot()
uses ggplot2 to draw plots as the ones produced by
terra::plot()
/terra::plotRGB()
in a single command.
Usage
## S3 method for class 'SpatRaster'
autoplot(
object,
...,
rgb = NULL,
use_coltab = NULL,
facets = NULL,
nrow = NULL,
ncol = 2
)
## S3 method for class 'SpatVector'
autoplot(object, ...)
Arguments
object |
A |
... |
other arguments passed to |
rgb |
Logical. Should be plotted as a RGB image? If |
use_coltab |
Logical. Should be plotted with the corresponding
|
facets |
Logical. Should facets be displayed? If |
nrow , ncol |
Number of rows and columns on the facet. |
Details
Implementation of ggplot2::autoplot()
method.
Value
A ggplot2 layer
Methods
Implementation of the generic ggplot2::autoplot()
function.
SpatRaster
Uses geom_spatraster()
or geom_spatraster_rgb()
.
SpatVector
Uses geom_spatvector()
. Labels can be placed with geom_spatvector_text()
or geom_spatvector_label()
.
See Also
Other ggplot2 utils:
fortify.Spat
,
geom_spat_contour
,
geom_spatraster()
,
geom_spatraster_rgb()
,
ggspatvector
,
stat_spat_coordinates()
Other ggplot2 methods:
fortify.Spat
Examples
file_path <- system.file("extdata/cyl_temp.tif", package = "tidyterra")
library(terra)
temp <- rast(file_path)
library(ggplot2)
autoplot(temp)
# With a tile
tile <- system.file("extdata/cyl_tile.tif", package = "tidyterra") %>%
rast()
autoplot(tile)
# With coltabs
ctab <- system.file("extdata/cyl_era.tif", package = "tidyterra") %>%
rast()
autoplot(ctab)
# With vectors
v <- vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))
autoplot(v)
v %>% autoplot(aes(fill = cpro)) +
geom_spatvector_text(aes(label = iso2)) +
coord_sf(crs = 25829)