Use the coordinates of the input raster to generate coordinate rasters, these are then used in a contour plot.

lonlat(
  x,
  na.rm = FALSE,
  lon = FALSE,
  lat = FALSE,
  ...,
  plot = TRUE,
  add = TRUE
)

Arguments

x

input raster

na.rm

logical, remove missing values from generated coordinates

lon

if TRUE, only longitude plotted

lat

if TRUE (and `lon = FALSE`) only latitude plotted

...

passed to [graphics::contour()]

plot

logical, plot the result

add

logical, add to current plot or instantiate one

Value

RasterBrick of the longitude and latitude values, two layers

(invisibly) the raster (RasterBrick) object with longitude and latitude values of the input as two layers, otherwise this function used for side-effect (drawing on a plot)

Details

Plot is added to an existing plot by default.

Examples

plot(c(-180, 180), c(-90, 90))
lonlat(raster::raster())


p <- raster::projectExtent(raster::raster(), "+proj=igh")
lonlat(p, add = FALSE)

lonlat(p, levels = seq(-180, 180, by  =15), add = FALSE)


lonlat(p, levels = seq(-180, 180, by = 5), add = FALSE, lon = TRUE)
lonlat(p, levels = seq(-180, 180, by = 15), add = TRUE, lat = TRUE)