im.ggplot {imageRy}R Documentation

Visualize a Raster Image Using ggplot2

Description

This function converts a 'SpatRaster' object into a 'ggplot2' visualization, allowing for flexible raster plotting with color interpolation.

Usage

im.ggplot(input_raster, layerfill = 1)

Arguments

input_raster

A 'SpatRaster' object representing the input raster image.

layerfill

An integer indicating the layer index to be used for coloring the raster (default: 1).

Details

This function extracts raster values, converts them into a data frame, and uses 'ggplot2' to visualize the raster with a viridis color scale.

- If 'layerfill' is not provided, the function defaults to using the first layer. - The function automatically handles coordinate extraction ('x' and 'y' values). - Colors are applied using 'scale_fill_viridis()', ensuring good perceptual readability.

Value

A 'ggplot' object displaying the raster image.

See Also

[im.classify()], [im.dvi()]

Examples

library(terra)
library(ggplot2)

# Create a sample raster
r <- rast(nrows = 10, ncols = 10)
values(r) <- matrix(runif(100), nrow = 10)

# Generate a ggplot visualization
im.ggplot(r)

[Package imageRy version 0.3.0 Index]