Documentation

13.23 Custom plot axes, smoothing, facets, and pages

After choosing kind, scope, and variables, a custom plot can control grouping, filtering, axes, statistical layers, and pagination. Each choice changes what the reader sees; keep the specification beside the figure.

Selection and grouping

filter applies an R-style row condition within the chosen scope. pk_only=true retains PK observations. by defines line groups (ID by default for line plots). color chooses colour groups; "none" disables the chapter-wide colour. facet creates panels, and "strata" reuses [eda].strata.

Axes and references

log_x/log_y request log scales; nonpositive values leave the plot and are counted in captions. xlim=[low,high] and ylim require ordered limits and can hide data without deleting it from underlying summaries. xlab, ylab, and title override text. hline, vline, and identity=true add reference lines, which must be justified and labeled in prose.

Statistics and appearance

smooth is loess, linear, power, or none; span controls LOESS, while smooth_by="group"|"all" chooses group-specific versus overall curves. Summary/bar plots use stat and error; bins controls summary/category binning and hist_bins histogram bars. points, lines, jitter, and legend adjust marks.

ncol, nrow, max_pages, and free="none"|"x"|"y"|"both" control facet layout. max_lines caps line groups. A cap changes what is displayed, so document the selection rule.

A useful verification is to create a companion listing containing the plotted variables, group, facet, and filter result. Compare its row count with the plot caption and manually locate the minimum, maximum, and a typical point. This connects presentation choices back to exact records.

Common mistakes

  • Using axis limits to hide inconvenient points.
  • Drawing an overall smoother across confounded groups.
  • Freeing facet scales and comparing visual slopes/magnitudes directly.
  • Jittering points without explaining that positions are displaced.

Checklist

  • Record filters and excluded nonpositive values.
  • Justify transformations and reference lines.
  • Match smoothing to the question and support.
  • Preserve comparable axes where comparison is intended.
  • Record page/line caps and review hidden groups.

Further reading

See custom kinds/scopes, summary statistics, and figure export.