Learn R Programming

tidyterra (version 0.3.0)

scale_fill_terrain: Terrain colour fill scales from grDevices

Description

Implementation of the classic color palettes used by default by the terra package (see terra::plot()). Three fill scales are provided:

  • scale_fill_terrain_d(): For discrete values.

  • scale_fill_terrain_c(): For continuous values.

  • scale_fill_terrain_b(): For binning continuous values.

Usage

scale_fill_terrain_d(..., alpha = 1, direction = 1)

scale_fill_terrain_c( ..., alpha = 1, direction = 1, na.value = NA, guide = "colourbar" )

scale_fill_terrain_b( ..., alpha = 1, direction = 1, na.value = NA, guide = "coloursteps" )

Value

The corresponding ggplot2 layer with the values applied to the fill aesthetics.

Arguments

...

Other arguments passed on to discrete_scale(), continuous_scale(), or binned_scale to control name, limits, breaks, labels and so forth.

alpha

The alpha transparency, a number in [0,1], see argument alpha in hsv.

direction

Sets the order of colors in the scale. If 1, the default, colors are ordered from darkest to lightest. If -1, the order of colors is reversed.

na.value

Missing values will be replaced with this value.

guide

A function used to create a guide or its name. See guides() for more information.

See Also

terra::plot(), ggplot2::scale_fill_viridis_c()

Other gradient scales and palettes for hypsometry: scale_fill_cross_blended, scale_fill_hypso, scale_fill_whitebox, scale_fill_wiki

Examples

Run this code
# \donttest{
filepath <- system.file("extdata/volcano2.tif", package = "tidyterra")

library(terra)
volcano2_rast <- rast(filepath)

library(ggplot2)
ggplot() +
  geom_spatraster(data = volcano2_rast) +
  scale_fill_terrain_c()

# Binned
ggplot() +
  geom_spatraster(data = volcano2_rast) +
  scale_fill_terrain_b(breaks = seq(70, 200, 10))

# With discrete values
factor <- volcano2_rast %>% mutate(cats = cut(elevation,
  breaks = c(100, 120, 130, 150, 170, 200),
  labels = c(
    "Very Low", "Low", "Average", "High",
    "Very High"
  )
))


ggplot() +
  geom_spatraster(data = factor, aes(fill = cats)) +
  scale_fill_terrain_d(na.value = "gray10")
# }

Run the code above in your browser using DataLab