Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The box mark could use bin/rect instead of group/bar for quantitative data #1330

Open
mbostock opened this issue Mar 14, 2023 · 4 comments
Open
Labels
enhancement New feature or request

Comments

@mbostock
Copy link
Member

mbostock commented Mar 14, 2023

As an approximation:

Plot.plot({
  marks: [
    Plot.ruleX(data, Plot.binX({y1: loqr1, y2: hiqr2}, {x, y})),
    Plot.rectY(data, Plot.binX({y1: "p25", y2: "p75"}, {x, y, fill: "#ccc"})),
    Plot.ruleY(data, Plot.binX({y: "p50"}, {x, y, strokeWidth: 2})),
    Plot.dot(data, Plot.map({y: oqr}, {x, y, z: ???}))
  ]
})

I couldn’t figure out how to compute the per-bin outliers, though. Maybe we need a Plot.binmapX transform where z can be imputed by binning x? Or maybe there’s a way to compose the bin and map transform? 🤔

Ref. https://talk.observablehq.com/t/how-to-label-a-boxplot-with-dates-format-axis/7739/3

@mbostock mbostock added the enhancement New feature or request label Mar 14, 2023
@Fil
Copy link
Contributor

Fil commented Mar 14, 2023

I feel this could be addressed at a higher abstraction level (#1336)?

@mbostock
Copy link
Member Author

I think we could use exactly the same technique we use in Plot.auto, then have the box mark chose dynamically between bin+rect and group+bar.

@Fil
Copy link
Contributor

Fil commented Apr 14, 2023

This is the test example in http://localhost:8008/?test=aaplMonthly (minus the outliers)

@mbostock
Copy link
Member Author

Here’s an example workaround:

untitled (55)

Plot.plot({
  y: {
    grid: true,
    label: "↑ Price"
  },
  x: {
    interval: 0.5,
    label: "Carats →",
    labelAnchor: "right",
    tickFormat: (x) => x.toFixed(1)
  },
  marks: [
    Plot.ruleY([0]),
    Plot.boxY(diamonds, {x: (d) => Math.floor(d.carat * 2) / 2, y: "price"})
  ]
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants