gf_function: Layers displaying graphs of functions

gf_functionR Documentation

Layers displaying graphs of functions


These functions provide two different interfaces for creating a layer that contains the graph of a function.


gf_function(object = NULL, fun, data = NULL, ..., inherit = FALSE)

gf_fun(object = NULL, formula, data = NULL, ..., inherit = FALSE)



When chaining, this holds an object produced in the earlier portions of the chain. Most users can safely ignore this argument. See details and examples.


A function.


A data frame with the variables to be plotted.


Additional arguments passed as params to layer(). This includes xlim, a numeric vector providing the extent of the x-axis values used to evaluate fun for plotting. By default, xlim is not used for other layers.


A logical indicating whether default attributes are inherited.


A formula describing a function. See examples and mosaicCore::makeFun().


gf_function(fun = sqrt, xlim = c(0, 10))
gf_dhistogram(~age, data = mosaicData::HELPrct, binwidth = 3, alpha = 0.6) |>
    fun = stats::dnorm,
    args = list(mean = mean(mosaicData::HELPrct$age), sd = sd(mosaicData::HELPrct$age)),
    color = "red"
gf_fun(5 + 3 * cos(10 * x) ~ x, xlim = c(0, 2))
# Utility bill is quadratic in month?
f <- makeFun(lm(totalbill ~ poly(month, 2), data = mosaicData::Utilities))
gf_point(totalbill ~ month, data = mosaicData::Utilities, alpha = 0.6) |>
  gf_fun(f(m) ~ m, color = "red")

ggformula documentation built on Nov. 9, 2023, 5:08 p.m.