Evaluates fn over the panel's x range and draws the result. Handy for overlaying a theoretical density or a reference curve on data.

geom_function(
  fn,
  xlim = c(0, 1),
  n = 101,
  color = NULL,
  linewidth = NULL,
  alpha = NULL
)

Arguments

fn

A function of one numeric argument.

xlim

Length-2 range to evaluate over.

n

Number of evaluation points.

color, linewidth, alpha

Appearance.

Value

A Layer to add with +.

Examples

ggnext(data.frame(x = c(-3, 3)), aes(x)) +
  geom_function(dnorm, xlim = c(-3, 3))
#> <ggnext plot>
#>   data:  2 x 1
#>   aes:   x = x
#>   layers: 1 
#>   coord: cartesian
#>   mode:  static