-
Hello! I'm using the group transformation to build bar marks, but I'd like to reuse the same transformation to show the resulting values within a text mark above the bar. What is the best way to do this? I understand I can rebuild the calculations directly in the data, but I wonder if there's any better alternative using the object resulting from Plot.groupX. Here's the example code I built: {
const xy = {
x: "species",
y: "body_mass_g"
};
const xy_group = Plot.groupX({ y: "mean" }, xy);
return Plot.plot({
marks: [
Plot.barY(penguins, {
...xy_group,
stroke: "navy"
}),
Plot.text(penguins, {
...xy_group,
lineAnchor: "bottom",
dy: -5,
text: (v) => d3.mean(v, (d) => d[xy.y]) // I would expect to somehow reuse xy_group here
})
]
});
} also availabe in this notebook |
Beta Was this translation helpful? Give feedback.
Answered by
Fil
Jan 15, 2025
Replies: 1 comment 7 replies
-
It does the computation once for each channel, but it should work. |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes; here's how it would work:
The text reducer is applied for each series (here, penguins) on the text channel.
Note that your current code computes a mean for every penguin, only to retain the first for each series.