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

docs: Add example of cumulative line chart with facet #3440

Merged
merged 3 commits into from
Jun 26, 2024

Conversation

dsmedia
Copy link
Contributor

@dsmedia dsmedia commented Jun 18, 2024

Description

This PR replaces the "Cumulative Wikipedia Donations" example with a new chart, based on issue #2424. The original example was broken and went against the Contribution guideline that requires local datasets, and a new faceted cumulative sum chart was proposed in 2021. This PR incorporates the suggestion made by @jakevdp to improve x-axis labels. The example was developed and proposed by @harabat, but had not been 100% finalized. I made some very small tweaks to get it working in Altair v5 and to incorporate small recommendations in #2424.

Changes Made

  • Introduced a new cumulative sum chart to replace the broken (and since-removed) example of Cumulative Wikipedia Donations.

The following code provides an illustration of a cumulative sum (to replace the broken chart), but also clarifies the styling of titles, headers, order, and marks of a facet plot, and gives an example of combining predicates with the filter transform.

Source: @harabat

  • Improved x-axis label formatting per @jakevdp suggestion.
  • Assigned to category of line charts. (@jakevdp in 2021 suggested this be categorized as a case study, but the example gallery has evolved significantly since then. This example builds on a simpler cumulative line example and seemed to be a good fit within that section.)

Issue Reference

Resolves #2424

facetline_cumsum

Copy link
Contributor

@joelostblom joelostblom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up @dsmedia! I made a few suggestions to improve the original example here. I also think this might be a better fit for the advanced calculation section in the gallery since as you noted there is already a cumulative chart in the line category and the most interesting thing here is probably the more intricate use of filters.

@mattijn
Copy link
Contributor

mattijn commented Jun 19, 2024

Ignore if you had a specific intend with the current scales, but I noticed there is a slight misalignment, especially the x-axis of 'epidemic' and 'flood'. This could be resolved by changing

.resolve_scale(y='independent')

to:

.resolve_axis(y='independent', x='independent')

Where the result will look like this:
image

But again, if the current approach was with a certain intend, then please ignore this comment.


Also linking #695. Maybe someone sees this as an opportunity to improve this current syntax

.transform_filter(
    {'and': [
        alt.FieldOneOfPredicate(field='Entity', oneOf=columns_sorted), # Filter data to show only disasters in columns_sorted
        alt.FieldRangePredicate(field='Year', range=[1900, 2000]) # Filter data to show only 20th century
    ]}
)

Since this:

alt.FieldOneOfPredicate(field='Entity', oneOf=columns_sorted) & alt.FieldRangePredicate(field='Year', range=[1900, 2000])

Returns currently:

TypeError: unsupported operand type(s) for &: 'FieldOneOfPredicate' and 'FieldRangePredicate'

@joelostblom
Copy link
Contributor

I like the change suggested by @mattijn to make the axes clearer. If you make that change @dsmedia we can go ahead and merge after.

@dsmedia
Copy link
Contributor Author

dsmedia commented Jun 20, 2024

Thanks for the suggestion, @mattijn. I've submitted the change.

@mattijn
Copy link
Contributor

mattijn commented Jun 26, 2024

Thanks looks good!

@mattijn mattijn merged commit 6b5a867 into vega:main Jun 26, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace the broken example "Cumulative Wikipedia Donations"
3 participants