observablehq / observablehq/plot

The map transform should maybe apply maybeApplyInterval?

Open
#1,842 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
HTML
Stars
5.4k
Forks
244
PR merge metrics
No merged PRs in 30d

Description

The map transform groups by y and not by intervaled y. If you replace y: (d) => ((d.height * 10) | 0) / 10 below by y: "height", the box plot shows too many outliers (the outliers are using a map transform).

Here's a test with the correct outliers:

export async function boxplotXInterval() {
  const olympians = await d3.csv<any>("data/athletes.csv", d3.autoType);
  return Plot.plot({
    y: {interval: 0.1, reverse: true},
    marks: [
      Plot.boxX(
        olympians.filter((d) => d.height),
        {x: "weight", y: "height", z: (d) => Math.floor(d.height * 10)}
      )
    ]
  });
}

correct

now, remove the z specified above, and you get this incorrect chart, where you have "outliers" inside the q1-q3 band:

incorrect

(excerpted from #1839; note that I've updated the code slightly to add y: {reverse: true}, for when we create the actual unit test.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the map transform and maybeApplyInterval behavior used by Plot.boxX, then compare it with the boxplotXInterval example in the issue. Add or update the unit test using the athletes data and verify that intervaled y grouping produces the correct outliers without explicitly supplying z.

Written by the indexing model from the issue text.

Assessment

Tech stack
d3, javascript
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.