Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

gplot-methods

Use ggplot to plot a Raster* or a SpatRaster object.


Description

A wrapper function around ggplot (ggplot2 package). Note that the function in the raster package is called gplot with a single 'g'.

Usage

## S4 method for signature 'Raster'
gplot(x, maxpixels=50000,...) 
## S4 method for signature 'SpatRaster'
gplot(x, maxpixels=50000,...)

Arguments

x

A Raster* or SpatRaster object

maxpixels

Maximum number of pixels to use

...

Additional arguments for ggplot

Author(s)

Robert J. Hijmans and Oscar Perpiñán; based on an example by Paul Hiemstra

See Also

Examples

## Not run: 
r <- raster(system.file("external/test.grd", package="raster"))

s1 <- stack(r, r*2)
names(s2) <- c('meuse', 'meuse x 2')

library(ggplot2)

theme_set(theme_bw())

## With raster
gplot(s1) + geom_tile(aes(fill = value)) +
          facet_wrap(~ variable) +
          scale_fill_gradient(low = 'white', high = 'blue') +
          coord_equal()

## With terra
s2 <- rast(s1)
gplot(s) + geom_tile(aes(fill = value)) +
          facet_wrap(~ variable) +
          scale_fill_gradient(low = 'white', high = 'blue') +
          coord_equal()

## End(Not run)

rasterVis

Visualization Methods for Raster Data

v0.50.2
GPL-3
Authors
Oscar Perpinan Lamigueiro [cre, aut] (<https://orcid.org/0000-0002-4134-7196>), Robert Hijmans [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.