get_contourlines: Get contour lines

Description Usage Arguments Examples

View source: R/anem_geoprocessing.R

Description

Get contour lines, using a wrapper for contourLines

Usage

1
2
get_contourlines(df = NULL, nlevels = 10, drop_outer = TRUE,
  levels = NULL, ..., type = "data.frame", crs = 4326)

Arguments

df

A data.frame containing x, y, and z columns. x and y must form a raster, meaning every x must be represented for each y, and vice versa.

nlevels

An integer containing number of levels to return. Used IFF levels not supplied.

drop_outer

If TRUE, nlevels+2 will be calculated, dropping the outer 2 values. Used IFF levels not supplied.

levels

A vector of values at which contours should be plotted. If used, nlevels is ignored.

...

Should contain x, y, and z, and then df will be ignored.

type

Should be either "data.frame" or "sf"

crs

The target crs for "sf" output. Used as input in sf::st_as_sf

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Example 1
df <- expand.grid(x=-10:10,y=-10:10)
df$z <- df$x^2
cl <- get_contourlines(df,nlevels=5)
unique(cl$level)

library(ggplot2)
ggplot() +
  geom_raster(data=df,aes(x,y,fill=z)) +
  geom_path(data=cl,aes(x,y,group=line))

cl <- get_contourlines(df,levels=c(15,20,60))
unique(cl$level)

# Example 2, with "sf" object
library(sf)
df <- expand.grid(x=seq(-5,5,length.out=20),y=seq(-5,5,length.out=20))
df$z <- sqrt(df$x^2+df$y^2)

cl <- get_contourlines(df,levels=seq(1,10,by=1.5), type="sf")
ggplot() +
  geom_raster(data=df,aes(x,y,fill=z)) +
  geom_sf(data=cl,aes())

gopalpenny/anem documentation built on Dec. 20, 2020, 5:27 a.m.