Published unlisted
Edited
May 14, 2022
Insert cell
Insert cell
Changed in base
-
textcolor("Solved!", "forestgreen")
+
textcolor("Plot Help", "firebrick")
Insert cell
Added in base
[Forum Discussion](https://talk.observablehq.com/t/make-a-bar-chart-with-text-count-labels-in-plot/6547)
Insert cell
Insert cell
Changed in base
-
--- ## 🤔 Getting around the problem with Arquero - Can make a separate dataset, then plot that instead.
+
## Getting around the problem with Arquero - Can make a separate dataset, then plot that
Insert cell
wrangled = aq.from(diamonds)
.groupby("cut")
.count()
.objects()
Insert cell
Plot.plot({
marginLeft: 50,
marks: [
Plot.barY(wrangled, {
x: "cut",
y: "count",
fill: "purple"
}),
Plot.text(wrangled, {
x: "cut",
y: "count",
text: "count",
dy: -8,
sort: {x: "y"}
}),

]
})
Insert cell
Changed in base
-
## Can solve using Plot Transforms - @mbostock: _"Try moving the text channel declaration to the output of the group transform rather than the input."_
+
## Is it possible within Plot using transforms? - Wanting to show the counts as above, but end up seeing the index. Can we access the group transform value?
Insert cell
Changed in base
Plot.plot({ marginLeft: 50, marks: [ Plot.barY(diamonds, Plot.groupX({y: "count"}, { x: "cut",
-
fill: "cornflowerblue"
+
fill: "firebrick"
})),
-
Plot.text(diamonds, Plot.groupX({text: "count", y: "count"}, { // can access "count" within group transform output
+
Plot.text(diamonds, Plot.groupX({text: "count", y: "count"}, {
x: "cut", dy: -8, sort: {x: "y"} })) ] })
Insert cell
Insert cell