Skip to content

Multiple bars side-by-side #1943

Answered by mbostock
Hvass-Labs asked this question in Q&A
Dec 9, 2023 · 2 comments · 6 replies
Discussion options

You must be logged in to vote

Probably you want to use faceting here, along x by Date, so that you have side-by-side bars for each day.

Plot.plot({
  grid: true,
  fx: {interval: "day"},
  x: {axis: null, padding: 0},
  y: {label: null},
  color: {legend: true},
  marks: [
    Plot.barY(data, {fx: "Date", y: "Value", x: "Name", fill: "Name"}),
    Plot.ruleY([0])
  ]
})

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

Note that your fx scale should declare the expected time interval (above day) so that you get nice ticks. If you don’t specify the interval, Plot won’t be able to guess the time interval of your data, and won’t be able to reduce the number of ticks in some sensible manner to reduce overlap.

For exa…

Replies: 2 comments 6 replies

Comment options

Fil
Dec 9, 2023
Collaborator

You must be logged in to vote
5 replies
@Hvass-Labs
Comment options

@Fil
Comment options

@Hvass-Labs
Comment options

@Fil
Comment options

@Hvass-Labs
Comment options

Comment options

You must be logged in to vote
1 reply
@Hvass-Labs
Comment options

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