Text + image as label of an horizontal bar chart in Plot #2263
-
I would like to have a y label composed of both text and image in an horizontal bar chart in Plot. Any hints at how it could be achieved? Is there a way to combine marks together (like a Plot.Text and an Plot.Image...if that would be a possible path to a solution)? I am lost... Any helps is welcome |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
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 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: "Portrait URL"
})
]
}) Likewise if you want text, you can add a text mark. If you want to combine marks, take a look at Plot.marks, or just write a function that returns an array of marks. |
Beta Was this translation helpful? Give feedback.
-
Ah, I haven't expressed myself clearly enough... |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
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:That fixed, you can simply add a Plot.image mark if you want an image.