Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example gallery should show how to mark and label the final value in a timeseries #2622

Closed
palewire opened this issue Jun 29, 2022 · 3 comments · Fixed by #2623
Closed

Example gallery should show how to mark and label the final value in a timeseries #2622

palewire opened this issue Jun 29, 2022 · 3 comments · Fixed by #2623

Comments

@palewire
Copy link
Contributor

Charts like this have become commonplace in the COVID pandemic. It would be great to include an example showing how to do it. I'd submit a pull request, but I don't know how to do it! If someone can show me how, I'll submit an example for the docs.

Screenshot from 2022-06-29 14-29-55

@joelostblom
Copy link
Contributor

joelostblom commented Jun 29, 2022

Agree! I think direct labeling is often preferred over legends and I recently came across this example (bottom of the page) in the VegaLite docs that uses argmax for this, which is nicer than the more manual pandas approaches that I have used myself previously. Would you like to make an attempt at translating that to Altair code in a PR?

@palewire
Copy link
Contributor Author

palewire commented Jun 29, 2022

Good idea. How's this look?

import altair as alt
from vega_datasets import data

source = data.stocks()

chart = alt.Chart(source).transform_filter(
    alt.datum.symbol != "IBM"  # A reducation of the dataset to clarify our example. Not required.
).encode(
    color=alt.Color("symbol", legend=None)
)

line = chart.mark_line().encode(
    x="date:T",
    y="price:Q"
)

label = chart.encode(
    x=alt.X('date:T', aggregate='max'),
    y=alt.Y('price:Q', aggregate={'argmax': 'date'}),
    text='symbol'
)

text = label.mark_text(align='left', dx=4)

circle = label.mark_circle()

line + circle + text

visualization

@palewire
Copy link
Contributor Author

The PR is submitted in #2623

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants