Format chart label values in a waterfall chart using ggplot

Viewed 484

I'm creating a waterfall chart using the code below. I would like to format the labels inside the bars with a dollar format. How can I accomplish this?

For example, for this first bar, I would like to format 101000 as $101K.

library(ggplot2)
library(waterfalls)

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

# create plot
waterfall(income)

This is what the plot looks like currently: enter image description here

1 Answers

The package scales provides some conveniant functions for formatting axis labels.

library(ggplot2)
library(waterfalls)
library(scales)

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

# create plot
waterfall(income, rect_text_labels = dollar(amount)) + 
  scale_y_continuous("", labels = dollar_format())
Related