Skip to content

Text + image as label of an horizontal bar chart in Plot #2263

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

You must be logged in to vote

The main problem with your notebook is that you haven’t specified the types with your CSV. The default types are strings, so you end up with the x scale being ordinal by default instead of linear. You can fix this by specifying typed: true when loading the CSV:

presidents = FileAttachment("us-president-favorability-1.csv").csv({typed: true})

That fixed, you can simply add a Plot.image mark if you want an image.

Plot.plot({
  marginLeft: 170,
  marks: [
    Plot.barX(presidents, {
      y: "Name",
      x: "Very Favorable %"
    }),
    Plot.image(presidents, {
      y: "Name",
      x: "Very Favorable %",
      dx: 12,
      r: 9,
      preserveAspectRatio: "xMidYMin slice",
      src: "…

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by mbostock
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@espinielli
Comment options

@espinielli
Comment options

Comment options

You must be logged in to vote
0 replies
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