Skip to contents

This function takes a RasterLayer object, converts it into a SpatialPixelsDataFrame and uses geom_tile to plot the data.

Usage

# S3 method for RasterLayer
gg(
  data,
  mapping = ggplot2::aes(x = .data[["x"]], y = .data[["y"]], fill = .data[["layer"]]),
  ...
)

Arguments

data

A RasterLayer object.

mapping

aesthetic mappings created by aes. These are passed on to geom_tile.

...

Arguments passed on to geom_tile.

Value

An object returned by geom_tile

Details

This function requires the raster and ggplot2 packages.

See also

Other geomes for Raster data: gg(), gm()

Examples

if (FALSE) {
# Some features require the raster and spatstat.data packages.
if (require("spatstat.data", quietly = TRUE) &&
  require("raster", quietly = TRUE) &&
  require("ggplot2", quietly = TRUE)) {
  # Load Gorilla data
  data("gorillas", package = "spatstat.data")

  # Convert elevation covariate to RasterLayer

  elev <- as(gorillas.extra$elevation, "RasterLayer")

  # Plot the elevation

  ggplot() +
    gg(elev)
}
}