简体   繁体   中英

Making a waterfall chart in R using the waterfall package?

I'm trying to use the waterfall R package to create a waterfall chart, like this, per the example at this link :

category <- c("Sales", "Services", "Fixed Costs", 
              "Variable Costs", "Taxes")
amount <- c(101000, 52000, -23000, -15000, -10000)
income <- data.frame(category, amount) 

library(ggplot2)
library(waterfalls)
waterfall(income) 

But getting this error:

Error in unit(rep(just$hjust, n), "npc") : 'x' and 'units' must have length > 0

How can I make it work?

This is the output from my sessionInfo()

R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] waterfalls_0.1.2 DBI_1.0.0        ggpubr_0.2       patchwork_0.0.1    forcats_0.4.0    stringr_1.4.0    dplyr_0.8.0.1    purrr_0.3.2     
[10] readr_1.3.1      tidyr_0.8.3      tibble_2.1.1     ggplot2_3.1.1    tidyverse_1.2.1  scales_1.0.0     lubridate_1.7.4  magrittr_1.5     RPresto_1.3.2   
[19] knitr_1.22       extrafont_0.17   bigrquery_1.1.1 

loaded via a namespace (and not attached):
 [1] nlme_3.1-139         sf_0.7-4             bit64_0.9-7          httr_1.4.0           tools_3.6.0          backports_1.1.4      rgdal_1.4-3          R6_2.4.0            
 [9] KernSmooth_2.23-15   rgeos_0.4-3          lazyeval_0.2.2       colorspace_1.4-1     raster_2.8-19        withr_2.1.2          sp_1.3-1             tidyselect_0.2.5    
[17] bit_1.1-14           curl_3.3             compiler_3.6.0       extrafontdb_1.0      cli_1.1.0            rvest_0.3.3          formatR_1.6          xml2_1.2.0          
[25] labeling_0.3         dygraphs_1.1.1.6     classInt_0.3-3       digest_0.6.18        foreign_0.8-71       rmarkdown_1.12       base64enc_0.1-3      pkgconfig_2.0.2     
[33] htmltools_0.3.6      jsonvalidate_1.0.0   htmlwidgets_1.3      rlang_0.3.4          readxl_1.3.1         rstudioapi_0.10      httpcode_0.2.0       shiny_1.3.2         
[41] generics_0.0.2       zoo_1.8-5            jsonlite_1.6         futile.logger_1.4.3  Rcpp_1.0.1           munsell_0.5.0        yaml_2.2.0           stringi_1.4.3       
[49] jqr_1.1.0            plyr_1.8.4           grid_3.6.0           settings_0.2.4       maptools_0.9-5       parallel_3.6.0       listenv_0.7.0        promises_1.0.1      
[57] crayon_1.3.4         geojsonio_0.7.0      miniUI_0.1.1.1       lattice_0.20-38      haven_2.1.0          geojson_0.3.2        hms_0.4.2            pillar_1.3.1        
[65] geojsonlint_0.3.0    codetools_0.2-16     futile.options_1.0.1 crul_0.7.4           glue_1.3.1           infuser_0.2.8        evaluate_0.13        V8_2.2              
[73] lambda.r_1.2.3       modelr_0.1.4         png_0.1-7            httpuv_1.5.1         Rttf2pt1_1.3.7       cellranger_1.1.0     gtable_0.3.0         future_1.12.0       
[81] RDruid_0.2.3         assertthat_0.2.1     xfun_0.6             mime_0.6             xtable_1.8-4         broom_0.5.2          e1071_1.7-1          later_0.8.0         
[89] class_7.3-15         units_0.6-2          globals_0.12.4      

I just found that not loading my company's internal package actually fixes this issue. There must be a function in my company's package that's breaking this package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM