In R/waterfalls package , how to make the label show in percent format

294 Views Asked by At

In R/waterfalls package , how to make the label show in percent format ? Thanks!

library(waterfalls)
waterfall(.data = data.frame(category = letters[1:5],
                             value = c(1, -0.2, 0.3, -0.1, -0.15)),
          fill_colours = colorRampPalette(c("#1b7cd6", "#d5e6f2"))(5),
          fill_by_sign = FALSE,
          calc_total = TRUE,
          total_axis_text='total' )
1

There are 1 best solutions below

0
anderwyang On

I have got the answer as below , just mark it .

 library(waterfalls)
    
    plot_data <- data.frame(category = letters[1:5],
                            value = c(1, -0.2, 0.3, -0.1, -0.15))
    
    waterfall(.data = plot_data,
              fill_colours = colorRampPalette(c("#1b7cd6", "#d5e6f2"))(5),
              fill_by_sign = FALSE,
              calc_total = TRUE,
              total_axis_text='total',
              rect_text_labels=scales::percent(plot_data$value,0.1),
              total_rect_text = scales::percent(sum(plot_data$value),0.1))