-
Notifications
You must be signed in to change notification settings - Fork 800
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
Percentage rather than counts #682
Comments
We just added window aggregates in Vega-Lite for this: vega/vega-lite#2488. They are not yet released, though. |
Hacky way of doing it now? (: |
You would need to do the groupby and counting in python (pandas) and then
use those values as the height of the bars.
…On Sat, Mar 31, 2018 at 6:04 AM, Christian Adam ***@***.***> wrote:
Hacky way of doing it now? (:
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#682 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABr0HJro3v4KtTqk1PJ-vXnYvzqXauvks5tj37ggaJpZM4TCG2s>
.
--
Brian E. Granger
Associate Professor of Physics and Data Science
Cal Poly State University, San Luis Obispo
@ellisonbg on Twitter and GitHub
bgranger@calpoly.edu and ellisonbg@gmail.com
|
Yes, you can totally precompute the normalized values in Python. In this case there is no need to do it in Vega-Lite itself. |
Window transforms are now in Altair; you can see an example here: https://github.com/altair-viz/altair/blob/4c344e79ebf619e762d5d220caab1b7a58996ac5/altair/vegalite/v2/examples/percentage_of_total.py Unfortunately, the JupyterLab renderer does not yet support vega-lite 2.4 yet, so it may not show up if you're using that frontend until a future release. |
@jakevdp just came across |
I see there is a |
Yes, Note that since this example was created, Altair added |
Oh, turns out it has already been updated: https://github.com/altair-viz/altair/blob/3541d9531974e6d9d0772e84bc662b96b78f5a2c/altair/examples/percentage_of_total.py#L14-L16 |
Awesome, thanks @jakevdp |
I'm wondering if it's possible to pass python functions to use as the aggregator for If I have a dataframe storing a collection of data points replicated for each value of the parameter of interest
But I assume passing |
No, aggregates in the spec are evaluated in the frontend (i.e. Javascript), so it's not possible to pass arbitrary Python functions as aggregates. You can either pre-compute your aggregations in Python to compute them in the backend, or express them via the specification to compute them in the frontend renderer. |
You can see a list of available frontend aggregations here: https://altair-viz.github.io/user_guide/encoding.html#encoding-aggregates |
Here's an attempt at expressing
|
The issue is
|
It looks like you want something like this (not tested): alt.Chart(
allLikelihoods
).transform_joinaggregate(
groupby = ['phi'], phiLikelihood = 'sum(logLikelihood)'
).transform_calculate(
logPhi = 'exp(datum.phiLikelihood)'
).transform_joinaggregate(
totalLikelihod = 'sum(logPhi)'
).transform_calculate(
logTotalLikelihood = 'log(totalLikelihood)'
) |
I'm trying to create a bar plot aggregating the data points into percentages. So I would like to do something like
but for the past hours I've completely failed to find a way of how to do that.
The text was updated successfully, but these errors were encountered: