Skip to content

Is Plot.barX(data, { y: (d) => makeY(d), ...}) equivalent to Plot.barX(data, { y: { value: (d) => makeY(d) }, ...}) ? #1869

Answered by mbostock
guizmaii asked this question in Q&A
Discussion options

You must be logged in to vote

As to the intent, I don’t follow the problem you describe, but based on the ASCII art that you shared here’s how I might produce a horizontal bar chart with a value label for each bar:

Plot.plot({
  x: {insetRight: 40, grid: true},
  marks: [
    Plot.barX(data, {y: "name", x: "value", fy: "facet", fill: "steelblue"}),
    Plot.ruleX([0]),
    Plot.text(data, {text: "value", y: "name", x: "value", fy: "facet", frameAnchor: "left", dx: 6}),
    Plot.frame(),
  ]
})

The data looks like this (CSV with name, value, and facet columns):

data = [
  {name: "a", value: 10, facet: 0},
  {name: "b", value: 14, facet: 0},
  {name: "c", value: 6, facet: 0},
  {name: "a", value: 14, facet: 1},
  {name: 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@guizmaii
Comment options

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