Documentation

13A.9 Plot grammar: layers and aesthetics

custom follows a ggplot2-like grammar. A plot combines prepared rows, aesthetic mappings, one or more geometric layers, coordinate/scaling choices, optional facets, and presentation settings. Understanding those pieces is more useful than memorising commands.

Plot grammar

Mappings versus constants

--color SEX maps the values of the SEX column to colours and creates a legend. --color red sets every mark to red when no column named red exists. The same principle applies to fill, shape, size, and linetype. x, y, group, and label are mappings.

Layering

Comma-separated geoms form layers: --geom point,smooth draws observations and a fitted trend; line,point,errorbar combines trajectories, centers, and uncertainty. Each layer receives the same prepared frame and mappings unless the geom internally summarises. Avoid layering incompatible grains. Raw points plus group summaries can be useful; raw lines plus a summarized error bar may require careful grouping to avoid a false connection.

Requirements

Point needs x and y. Histogram needs numeric x. Text needs x, y, and label. Boxplot and violin need y and usually a categorical x. Tile needs x and y and optionally a fill variable. Missing required aesthetics are rejected with a targeted message.

The full catalogue is printed by nlmx custom --list-plots. The frozen gallery renders every geom so that syntax and output are testable rather than aspirational.

Common mistakes

  • Confusing a fixed colour with a mapped colour.
  • Layering outputs based on different implicit grains.
  • Choosing a geom before defining the analytical question.
  • Assuming a smooth or density is raw data.

Checklist

  • State the prepared row grain.
  • Identify each mapped variable and fixed appearance.
  • Confirm every layer's statistical transformation.
  • Review legends and grouping.
  • Compare the picture with source counts.

Further reading

Continue with point, jitter, and text, trajectories, aesthetic mappings, and geom families.