-
Notifications
You must be signed in to change notification settings - Fork 52
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
How to properly apply y limits on the entire plot in a stacked bar plot? #978
Comments
Hi, yes, it seems However, stacked bars poses a kind of discrepancy between user's expectations and how scale's limits work. As a workaround try applying coordinate system limits: |
Hey @alshan ! Thanks for your prompt response, the workaround worked exactly as expected! Though, what's the difference between adding |
That's right, "coord limits" work as a visual zooming. With "scale limits", the key difference is that setting these limits discards all data outside the range. Here is the relevant chapter: Zooming into a plot with coord_cartesian(). |
@alshan Hey! One more related issue: When attaching numerical labels to corresponding stacked bars via I tried to manually add the labels via While the Adding what's equivalent to the |
Hi, regarding annotation labels on bars - congrats, you nailed a bug :) : #981 As for
Could you provide a minimal example? In the demo above value 0.5 works as expected (see
Yes, we are planning to expand annotations API in this direction. Hopefully sooner than later. |
Hey @alshan ! Regarding the use of the Anyways, when adding it in the example mentioned in the first post:
It doesn't quite do anything (even with adding The way I'm doing it right now is by addting a "height" column to my dataframe (using the I then use that height in
And regarding the use of
that way, it doesn't work as expected:
Thanks a lot! |
You are right, as long as you map color aesthetic in In your code snippet:
You forgot to add label coordinates:
so that both layers could share it.
As far as I can see you don't have
Clever trick ) Hopefully you wan't need it. |
Hey @alshan , Thanks for your help and comments as usual! Sorry, I know this discussion is quite old, but I would like to point out, that in this case, where you have drastic differences between stacked bar values (heights), the current best solution (given that
Which produces the following plot: However, this is still suboptimal. Would it perhaps be possible if the (P.S. when adding |
Hi @OSuwaidi
This is fixed already - will work in the next release.
Maybe. This situation we couldn't figure out how to handle on bar-charts.
Thanks, this likely a bug. |
…on't work for bars/area [[LPK-219](JetBrains/lets-plot-kotlin#219)], [[#978](#978)].
Hi @OSuwaidi , the issue with "scale limits" was fixed in v4.3.0. Note however that "coord system limits" is still a better way to zoom charts. Also, since v4.3.0, you don't have to set the upper limit here : |
Hey @alshan 👋🏼! Big, great changes in v4.3.0! Yet to try out and test all of them. The Great changes overall! |
The space above is the effect of the scale "expand". By default, continuous Y-scale has a multiplicative expand 0.05 (i.e. scale domain * 0.05). |
I have this data which represents the sales decomposition from high-level to granular, left to right (hence sum over the
index
column should add up to "total_revenue"):However, due to the nature of the data, there is drastic difference in the values of
sales_value
. Hence, when visualizing it via a stacked bar plot as follows:Some of the stacked bars on the top are way too small compared to the bars below:
I tried to "refactor" this by lower bounding the y limit to "zoom in" and highlight the small, stacked bars on top by doing:
+ ylim(120000, 138000)
, but that applied the y limit constraint on each bar individually in the stacked bar plot, making the bars with small y values disappear instead!I tried adding
+ scale_y_continuous(breaks={f'{i}': i for i in range(120000, 138001, 1000)})
but that didn't shift the y scale up either.I can't apply a log scale on the y values either because then the stacked values won't add up to the same total amount.
Any workaround for this?
The text was updated successfully, but these errors were encountered: