R package to create waterfall charts
hughparsonage / waterfalls Goto Github PK
View Code? Open in Web Editor NEWR package to create waterfall charts
License: Other
R package to create waterfall charts
License: Other
If I flip my waterfalls around using coord_flip()
in ggplot2
the "start" bar is on the bottom and the total on top, when most would expect to read top to bottom.
For example:
waterfall(
tibble(category = letters[1:5],
value = c(200, -20, 4, 20, -5)),
calc_total = TRUE,
fill_by_sign = FALSE,
put_rect_text_outside_when_value_below = 50
) + coord_flip()
I would typically add + scale_x_reverse()
to my ggplot
object, but in this case it results in:
Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing
scale.
Error: Discrete value supplied to continuous scale
In addition: Warning messages:
1: In Ops.factor(x) : ‘-’ not meaningful for factors
2: Transformation introduced infinite values in continuous x-axis
I love the package a lot. However, I didn't find a way to adjust the size of the text in X axis? Am I missing something or will this be in the future version?
Thanks,
I'm loving your waterfalls package and am so glad I don't have to build these up from scratch! Thank you so much for making this available.
I've run into an interesting edge scenario, however. I like to flip my waterfalls around using coord_flip()
in ggplot2
. But when I do, the text labels get bumped around.
For example:
waterfall(
tibble(category = letters[1:5],
value = c(200, -20, 4, 20, -5)),
calc_total = TRUE,
fill_by_sign = FALSE,
put_rect_text_outside_when_value_below = 50
) + coord_flip()
I'm beginning to dig into the code and if I cook up a solution I'll send a PR. But I wanted to register the issue first.
From https://twitter.com/DerFredo/status/952602226782101504
Great package indeed. Slight drawback: in the case of negative elements being involved, the Y-axis gets stretched to the max value of the negatives, even in case that’s not necessary because it’s only part of a more positive calculation. Any chance of a fix, Hugh?
Love the chart, but I want to add some axis labels and I can't. Reproducible example:
waterfall(values = round(rnorm(5), 1), labels = letters[1:5], calc_total = TRUE) + ylab("Why can't I add a y axis label?")
R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22000)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8 LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C LC_TIME=English_United States.utf8
time zone: America/Chicago
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_3.5.1 waterfalls_1.0.0
loaded via a namespace (and not attached):
[1] vctrs_0.6.5 cli_3.6.2 rlang_1.1.3 generics_0.1.3 textshaping_0.3.7 glue_1.7.0
[7] labeling_0.4.3 colorspace_2.1-0 rprojroot_2.0.4 ragg_1.3.0 scales_1.3.0 fansi_1.0.6
[13] grid_4.4.0 munsell_0.5.1 tibble_3.2.1 lifecycle_1.0.4 compiler_4.4.0 dplyr_1.1.4
[19] pkgconfig_2.0.3 here_1.0.1 rstudioapi_0.16.0 farver_2.1.1 systemfonts_1.0.6 R6_2.5.1
[25] tidyselect_1.2.1 utf8_1.2.4 pillar_1.9.0 magrittr_2.0.3 tools_4.4.0 withr_3.0.0
[31] gtable_0.3.5
My gratitude to you for this package.
I made a small hack to work around a limitation:
Using coord_cartesian(ylim=c(0.6, 0.72)) to zoom in to plot caused my rect_text_labels to land outside of the range and disappear. Not currently in a position to submit a pull request due to work firewall, but my fix was to replace rect_text_labels_anchor = "centre" with rect_text_labels_anchor = 0.05 and treat it as numeric. Then replace the two places that 0.5 were used to set it with the var name. Now, I can set it at 0.9 when combined with the coord_cartesian and the rect_text_labels no longer drop.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.