Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

gf_function

Layers displaying graphs of functions


Description

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

Usage

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

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

Arguments

object

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.

fun

A function.

xlim

A numeric vector providing the extent of the x-axis when creating the first layer in a plot. Ignored when creating a subsequent layer.

...

Other arguments such as position="dodge".

inherit

A logical indicating whether default attributes are inherited.

formula

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

Examples

gf_function(fun = sqrt, xlim = c(0, 10))
gf_dhistogram(~age, data = mosaicData::HELPrct, binwidth = 3, alpha = 0.6) %>%
  gf_function(
    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

Formula Interface to the Grammar of Graphics

v0.10.1
MIT + file LICENSE
Authors
Daniel Kaplan [aut], Randall Pruim [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.