Learn R Programming

ggformula (version 0.4.0)

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, fun, ...)

gf_fun(object, formula, ...)

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.

...

Other arguments such as position="dodge".

formula

A formula describing a function. See examples.

Examples

Run this code
# NOT RUN {
if (require(mosaicData)) {
  gf_histogram(..density.. ~ age, data = HELPrct, binwidth = 3, alpha = 0.6) %>%
    gf_function(fun = dnorm,
      args = list(mean = mean(HELPrct$age), sd = sd(HELPrct$age)),
      color = "red")
}
gf_point(Sepal.Length ~ Sepal.Width, data = iris) %>%
gf_fun(5 + 3 * cos(10 * x) ~ x)
# Utility bill is quadratic in month?
if (require(mosaic)) {
  f <- makeFun(lm(totalbill ~ poly(month, 2), data = Utilities))
  gf_point(totalbill ~ month, data = Utilities, alpha = 0.6) %>%
    gf_fun(f(m) ~ m, color = "red")
  }
# }

Run the code above in your browser using DataLab