Skip to contents

A serializable description of a scatter chart: which columns it binds, its semantics, and its appearance. Build one with setup_ScatterConfig() rather than calling this constructor directly.

Usage

ScatterConfig(
  dat_path = NULL,
  title = NULL,
  origin = NULL,
  writer = NULL,
  legend_position = "top",
  legend_placement = "outside",
  x = NULL,
  y = NULL,
  size = NULL,
  group = NULL,
  hover = NULL,
  fit_name = NULL,
  rug = FALSE,
  fit = NULL,
  se = TRUE,
  se_times = 1.96,
  rsq = FALSE,
  diagonal = FALSE,
  diagonal_color = NULL,
  n_fit = 200L,
  fit_alpha = 0.25,
  palette = NULL,
  square = FALSE,
  equal_axes = FALSE,
  pad = 0.04,
  xlim = NULL,
  ylim = NULL,
  xlab = NULL,
  ylab = NULL,
  margin_top = NULL,
  margin_right = NULL,
  margin_bottom = NULL,
  margin_left = NULL
)

Arguments

dat_path

Optional Character: Path to the data, read at draw time. The serializable alternative to passing data to draw().

title

Optional Character: Chart title. Declared here because it is the one property every chart type has; palette is not (four take a colormap instead), and axis labels and margins are cartesian-only.

origin

Optional Named character {"user", "default", "derived"}: Where each value came from, one entry per settable property. Absent on an authored config; written by the interface that resolved it.

writer

Optional Named character: Which interface wrote the config, as name and version. Absent on an authored config.

legend_position

Character {"top", "bottom", "left", "right", "top-left", "top-right", "bottom-left", "bottom-right"}: Legend anchor. Top/bottom anchors use horizontal rows; left/right anchors use a vertical column. Corner anchors align within the top or bottom row.

legend_placement

Character {"outside", "inside"}: Relation to the plotting area. Outside placement reserves space for the complete legend; inside placement overlays the data. Neither setting adds a missing legend.

x, y

Optional Character: Columns drawn on each axis.

size

Optional Character: Column giving per-point size.

group

Optional Character: Column to group and color points by.

hover

Optional Character: Column containing per-observation tooltip labels.

fit_name

Optional Character: Label for fitted layers.

rug

Logical: Show marginal marks along the x and y axes.

fit

Optional Character {"glm", "gam"}: Fit to overlay. NULL draws no fit.

se

Logical: If TRUE, shade the fit standard-error band.

se_times

Numeric [0, Inf): Multiplier for the fitted standard error.

rsq

Logical: Include the fitted model's R-squared in series labels.

diagonal

Logical: Draw the identity line within the axis limits.

diagonal_color

Optional Character: Identity-line color.

n_fit

Integer [2, Inf): Points used to draw the fit line.

fit_alpha

Numeric [0, 1]: Opacity of the standard-error band.

palette

Optional Character: Series colors, overriding the theme palette for this chart. NULL uses the theme's.

square

Logical: If TRUE, draw the plotting box square – equal height and width in pixels, excluding axis labels and margins.

equal_axes

Logical: If TRUE, give one data unit the same size in pixels on both axes. Set with square for a plot that is both, such as a true-versus-predicted plot whose identity line runs at 45 degrees; the two axes are then made to span the same interval.

pad

Numeric [0, Inf): Fraction of the data range to extend each axis by when xlim / ylim are not given. The default matches base R's xaxs = "r", which extends the range by 4% at each end.

xlim, ylim

Optional Numeric: Axis limits, length 2. NULL derives them from the data, padded by pad.

xlab, ylab

Optional Character: Axis labels. NULL derives them from the data.

margin_top, margin_right, margin_bottom, margin_left

Optional Integer [0, Inf): Plot margins in pixels.

Value

ScatterConfig object.

Details

The data-binding properties (x, y, size, group) hold column names, not values. The values come from the data argument to draw(), or from the inherited dat_path.

Margins are declared as four scalars rather than one named vector: that is what states cleanly in a schema, while draw_scatter() keeps the convenient margins vector. Sides left NULL fall back to the chart's own layout.

Author

EDG

Examples

cfg <- setup_ScatterConfig(x = "wt", y = "mpg", fit = "glm")
cfg@type
#> [1] "scatter"