Repository navigation
Conversation
|
It's not only about bars—other marks such as rect and area also have an implicit base value = 0. An alternative would be to write:
On a more philosophical note I'm struggling to know what to recommend in that case, because in general, bar charts typically encode quantities that can be added (and stacked), and addition only works well with a linear scale. Back to your notebook, I like what you did in the last example with Here are two other approaches I've tried:
Plot.plot({
marks: [
Plot.barX(data, Plot.mapX(X => X.map(d => Math.log10(d)), {x: "count", y: "letter"}))
],
x: {tickFormat: d => 10**d},
grid: true
})
Plot.plot({
marks: [
Plot.barX(data, {
x: "count",
y: "letter",
offset: (index, start, end, z) => {
for (const stack of index) {
for (const series of stack) {
for (const i of series) start[i] = 1 + start[i];
}
}
}
})
],
x: { type: "log" },
grid: true
})Note that the offset strategy allows to stack values, but makes it even harder to make sense of the resulting chart, because you basically have to do a reverse mental calculation. |
|
Revising this, an alternative might be to change the bar section, where it has: "this is the typical configuration for a vertical bar chart with bars aligned at y = 0" we could add " (note that this supposes that the y scale is linear, or at the very least can represent 0)." This would be correct in a sense, but alas I'm not sure it would help anyone figure out what they're doing wrong… I'll close the suggestion for now, because I don't see how we can address this properly—maybe it's more something for a tutorial. More suggestions are still welcome! |
This adds a hint that bars must include an explicit start and end so that the domain doesn't include zero when using log scales.
See #1038.