observablehq/plot

Make marks an argument to `plot`

vwkd opened this issue · 2 comments

vwkd commented

Marks seem to be the only concept that are explicitly named by the marks option in Plot.plot. Other concepts like channels, scales, transforms, etc. seem to not be named directly and instead are implicit in the options for the thing they apply to, e.g. x and color for scale.

Since there can be multiple marks, it makes sense to nest an array in some marks option. Maybe it’s also helpful for education to draw attention to the difference between modular marks and fixed charts.

To me it had the opposite effect though. Being confronted heads-on with this unknown “marks” concept felt inhibiting. Instead of feeling comfortable to learn the API by experimenting with it, I felt the need to having to study first what these new concepts even mean.

Marks seem to be the most fundamental arguments to a plot. A plot doesn’t do much without a mark, while the other options have sane defaults. It seems unintuitive to nest the most important thing three levels deep, while other optional things go a level higher.

Suggestion: Why not make marks a top-level argument to Plot.plot?

For example, the marks array could be the first argument, with the rest of the options bag going second.

Plot.plot([
    Plot.rectY(olympians, Plot.binX({y: "count"}, {x: "weight"})),
    Plot.ruleY([0]),
  ], {
  grid: true,
})

I believe this could help make Observable Plot more approachable, by not confronting the reader with the new “marks” concept heads-on similar to other concepts like scales.

If you want a “marks-first” approach, you can try Plot.marks.

untitled - 2024-02-19T124121 977

Plot.marks(
  Plot.rectY(olympians, Plot.binX({y: "count"}, {x: "weight"})),
  Plot.ruleY([0])
).plot({
  grid: true
})

Notebook: https://observablehq.com/d/a7a01e1a50b08c73

I don’t think we should overload Plot.plot to take an array of marks, though.

I meant to also say thank you for sharing your feedback and suggestion. Thank you!