Learn R Programming

ggformula (version 0.4.0)

gf_density2d: Formula interface to geom_density2d()

Description

ggformula functions provide a formula interface to ggplot2 layer functions. For plots with just one layer, the formula interface is more compact and is consistent with modeling and mosaic notation. The functions generate a ggplot command string which can be displayed by setting verbose = TRUE as an argument.

Usage

gf_density2d(object = NULL, gformula = NULL, data = NULL, geom = type,
  verbose = FALSE, add = inherits(object, c("gg", "ggplot")), ...,
  position = NULL, show.help = NULL)

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.

gformula

A formula with shape y ~ x. Faceting can be acheived by including | in the formula.

data

A data frame with the variables to be plotted.

geom

A way to specify ggplot geoms that are not aliased to gf functions.

verbose

If TRUE print the ggplot2 command in the console.

add

If TRUE then construct just the layer with no frame. The result can be added to an existing frame.

...

Additional arguments. Typically these are (a) ggplot2 aesthetics to be set with attribute = value, (b) ggplot2 aesthetics to be mapped with attribute = ~expression, or (c) attributes of the layer as a whole, which are set with attribute = value. Available attributes include alpha, color, group, linetype, size, contour, n, h, lineend, linejoin, linemitre

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

show.help

If TRUE, display some minimal help.

Value

a gg object

Details

Positional aesthetics are typically specified using a formula (see the gformula argument). Additional formula terms of the form + attribute::value map attribute to value. Additional terms of the form + attribute:value will map attribute to value if value is the name of a variable in data, else attribute will be set to the constant value. Alternatively (and preferably) attributes can be set can be set using arguments of the form attribute = value or mapped using arguments of the form attribute = ~ expression. In formulas of the form A | B, B will be used to form facets using facet_wrap() or facet_grid(). This provides an alternative to gf_facet_wrap() and gf_facet_grid() that is terser and may feel more familiar to users of lattice.

Evaluation of the ggplot2 code occurs in the environment of gformula. This will typically do the right thing when formulas are created on the fly, but might not be the right thing if formulas created in one environment are used to create plots in another.

See Also

geom_density2d()

Examples

Run this code
# NOT RUN {
if (require(mosaicData)) {
  gf_jitter(i1 ~ age, alpha = 0.2, data = HELPrct, width = 0.4, height = 0.4) %>%
  gf_density2d(i1 ~ age, data = HELPrct)
}
# }

Run the code above in your browser using DataLab