Skip to content

How to make ticks display more reasonably in BarX #2106

Answered by mbostock
Kiss-World asked this question in Q&A
Discussion options

You must be logged in to vote

To illustrate the options described by @Fil and @that-ambuj, here is what rect + bin would look like:

Plot.plot({
  height: 500,
  x: {
    label: "← men · population (thousands) · women →",
    labelAnchor: "center",
    tickFormat: Math.abs
  },
  marks: [
    Plot.rectX(
      population,
      Plot.binY(
        { x: "sum" },
        {
          x: (d) => d.population * (d.sex === "M" ? -1 : 1),
          y: "age",
          fill: "sex",
          interval: 1
        }
      )
    )
  ]
})

And here is what the interval option would look like (also using reverse to put zero at the bottom since ordinal y scales otherwise put the first value on top by default):

Plot.plot({
  height: 500,

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Kiss-World
Comment options

Answer selected by Kiss-World
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants