im.ggplot | R Documentation |
This function converts a 'SpatRaster' object into a 'ggplot2' visualization, allowing for flexible raster plotting with color interpolation.
im.ggplot(input_raster, layerfill = 1)
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). |
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.
A 'ggplot' object displaying the raster image.
[im.classify()], [im.dvi()]
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.