Skip to contents

Adds 2D kernel density estimate contours. Use filled = TRUE for filled density bands via ggplot2::geom_density_2d_filled.

Usage

mark_density_2d(
  plot,
  mapping = NULL,
  data = NULL,
  position = NULL,
  ...,
  filled = FALSE,
  bins = NULL,
  rasterize = FALSE,
  rasterize_dpi = 300,
  rasterize_dev = "cairo"
)

Arguments

plot

A plotit object

mapping

Optional new aesthetics

data

Optional data for this layer

position

Position adjustment.

...

Other arguments passed to the underlying geom

filled

If TRUE, use filled density contours.

bins

Number of contour bins (for filled mode).

rasterize

If TRUE, rasterize via ggrastr::rasterise().

rasterize_dpi

DPI for rasterization (default 300).

rasterize_dev

Graphics device for rasterization (default "cairo").

Value

Modified plotit object

References

AntV G2: Density (corelib, contour mode)

Examples

plotit(iris, encode(x = Sepal.Width, y = Sepal.Length)) |>
  mark_density_2d()