# NOT RUN {
# Avg temperature on spring in Castille and Leon (Spain)
file_path <- system.file("extdata/cyl_temp.tif", package = "tidyterra")
library(terra)
temp_rast <- rast(file_path)
library(ggplot2)
# Display a single layer
names(temp_rast)
ggplot() +
geom_spatraster(data = temp_rast, aes(fill = tavg_04)) +
# You can use coord_sf
coord_sf(crs = 3857) +
scale_fill_terrain_c()
# Display facets
ggplot() +
geom_spatraster(data = temp_rast) +
facet_wrap(~lyr, ncol = 2) +
scale_fill_terrain_b()
# Non spatial rasters
no_crs <- rast(crs = NA, extent = c(0, 100, 0, 100), nlyr = 1)
values(no_crs) <- seq_len(ncell(no_crs))
ggplot() +
geom_spatraster(data = no_crs)
# Downsample
ggplot() +
geom_spatraster(data = no_crs, maxcell = 25)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab