Skip to contents

mark_tile() draws a rectangular tile at each (x, y) coloured by fill; mark_raster() draws the same as one raster image (a fast path requiring a complete regular grid). mark_bin2d() bins continuous x/y into a grid and colours each cell by count. mark_density() draws a 1-D kernel density of x as a filled curve. On all of them a color given alongside a fill (or the default count fill of mark_bin2d() / mark_hex()) outlines the shapes; a color alone fills them. Unmapped, tiles, rasters and densities fill with col_mix(ink, paper, 0.2) from the theme's element_geom() ("grey20" on a light theme), the fill of ggplot2's geom_tile() and geom_area(). (ggplot2's geom_density() draws an unfilled outline; mark_density() keeps its filled curve, filled like an area.)

Usage

mark_tile(
  plot,
  ...,
  position = "identity",
  blend = NULL,
  sketch = NULL,
  data = NULL
)

mark_raster(plot, ..., position = "identity", blend = NULL, data = NULL)

mark_bin2d(
  plot,
  ...,
  position = "identity",
  bins = 30,
  blend = NULL,
  data = NULL
)

mark_density(
  plot,
  ...,
  position = "identity",
  adjust = 1,
  trim = FALSE,
  blend = NULL,
  sketch = NULL,
  data = NULL
)

mark_hex(
  plot,
  ...,
  position = "identity",
  bins = 30,
  blend = NULL,
  data = NULL
)

Arguments

plot

A PlotSpec (from vplot()).

...

Encodings (tidy-eval): x, y, fill for tile/raster; x, y for bin2d; x (+ fill/color) for density. mark_tile() also takes width and height (data units; default the resolution, so tiles abut). On a continuous axis the tiles' edges train the scale, as in ggplot2, so the end tiles are not clipped.

position

Position adjustment: a string — "identity" (default), "nudge", "stack", "fill", "dodge", "dodge2", "jitter", "jitterdodge", "sina" — or a parameterised position object such as position_dodge() or position_stack(). Every mark takes "identity" and "nudge". "stack"/"fill" work on bars, areas, points, text and labels (so a label can sit on its stacked bar); "dodge"/"dodge2" on bars, points, text, labels, error bars, line/point ranges, cross-bars, box plots, violins and slab-intervals (so error bars dodge over dodged bars); "jitter" on points, text and labels; "jitterdodge" and "sina" on points. A position a mark does not support is an error naming the ones it does.

blend

Optional blend mode for compositing this layer against what is already drawn beneath it (the panel and earlier layers), one of the CSS mix-blend-mode names, e.g. "multiply", "screen", "darken". The whole layer composites as one isolated group (not per element).

sketch

A sketch() spec giving this layer a hand-drawn look (wobbly outlines, hachure fills), NA/FALSE to force it crisp (overriding a plot-wide theme_sketch()), or NULL (default) to inherit. Geometry marks accept it; text, raster, hex and datashade marks do not.

data

Optional layer data frame; overrides the plot data for this layer.

bins

Number of bins per axis for mark_bin2d() / hex columns for mark_hex().

adjust

Bandwidth multiplier for mark_density().

trim

For mark_density(), FALSE (default) estimates every group's density over the range of the whole layer's x, as ggplot2 does; TRUE trims each group's curve to the range of its own data. The curve never runs past the data, so the axis is not padded by the kernel's tails.

Value

The modified PlotSpec.

Details

mark_density() draws its fill at 80% opacity, so a single curve reads lighter and overlapping groups show through each other. An alpha you set or map replaces the 0.8, and an outline (a color beside a fill) stays opaque.

With its count fill turned off (fill = NULL), mark_hex() fills with ggplot2's col_mix(ink, paper, 0.5) ("grey50" on a light theme). On a theme whose panel is that same grey, such as theme_dark(), it uses col_mix(ink, paper, 0.2) ("grey20") instead, so the hexes stay visible. This differs from ggplot2, which draws grey50 hexes on theme_dark()'s grey50 panel.

Examples

d <- expand.grid(x = 1:5, y = 1:5)
d$z <- d$x * d$y
vplot(d) |> mark_tile(x = x, y = y, fill = z)