Simpler way to achieve labelled bar graph #2988
-
Is this still the simplest way to achieve a labelled bar graph? https://altair-viz.github.io/gallery/bar_chart_with_labels.html Is there a way to do this without layering? Possibly an encoding I am not aware of? |
Beta Was this translation helpful? Give feedback.
Answered by
joelostblom
Mar 24, 2023
Replies: 1 comment 14 replies
-
You will need to layer two marks to have both bars and text in the same chart. Having that said, the syntax of the example you linked could be more succinct: bars = alt.Chart(source).mark_bar().encode(
x='wheat',
y="year:O",
text='wheat'
)
bars + bars.mark_text(align='left', dx=1) This looks pretty readable to me, but I'm curious to hear what you had in mind for the syntax and if you have encountered issues with the layering approach. |
Beta Was this translation helpful? Give feedback.
14 replies
Answer selected by
mcp292
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You will need to layer two marks to have both bars and text in the same chart. Having that said, the syntax of the example you linked could be more succinct:
This looks pretty readable to me, but I'm curious to hear what you had in mind for the syntax and if you have encountered issues with the layering approach.