Regression Scatterplot Recipe

Cars scatterplot with grouped regression lines and confidence bands
Layered points, derived fits, and confidence bands.

Use this pattern to layer grouped linear fits and mean-response confidence bands over a point chart.

Minimal flow

Runnable: install ggaction and provide the named data array as plain row objects.

import { chart } from "ggaction";

const program = chart()
  .createCanvas({
    width: 760,
    height: 480,
    margin: { top: 40, right: 190, bottom: 70, left: 80 }
  })
  .createData({ values: cars })
  .createPointMark()
  .encodeX({ field: "Displacement", scale: { nice: true, zero: false } })
  .encodeY({ field: "Acceleration", scale: { nice: true, zero: false } })
  .encodeColor({ field: "Origin", scale: { palette: "tableau10" } })
  .encodeSize({ field: "Acceleration" })
  .encodeShape({ field: "Origin" })
  .encodeOpacity({ value: 0.27 })
  .filterMarks({
    field: "Origin",
    op: "oneOf",
    values: ["Japan", "USA"]
  })
  .createRegression()
  .createGuides();

You must decide

The library infers

Pass target, x, y, or groupBy only when inference is ambiguous.

Continue

Regression scatterplot tutorial · Regression API · Appearance encodings