get_contours: Get contour lines

Description Usage Arguments Examples

View source: R/game_evaluate.R

Description

Get contour lines, using a wrapper for contourLines

Usage

1

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.

levels

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

...

If x, y, and z are directly specified here, df will be ignored.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
library(ggplot2)

df <- expand.grid(x=-10:10,y=-10:10)
df$z <- df$x^2
cl <- get_contours(df,levels=5)
unique(cl$level)
ggplot() +
  geom_raster(data=df,aes(x,y,fill=z)) +
  geom_path(data=cl,aes(x,y,group=line))

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

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_contours(df,levels=seq(2,10,by=2))
ggplot() +
  geom_raster(data=df,aes(x,y,fill=z)) +
  geom_path(data=cl,aes(x,y,group=line)) + coord_equal()

gopalpenny/genevoisgame documentation built on Sept. 9, 2020, 1:46 a.m.