Description Usage Arguments Examples
View source: R/anem_geoprocessing.R
Get contour lines, using a wrapper for contourLines
1 2 |
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 |
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 |
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())
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.