0

I need to present data to a non-technical audience and wanted to try a scale that uses abbreviated text with a mix of numbers. I'm fairly certain that this can be accomplished with scales package and ggplot, but I'm stuck on how to implement this.

For instance, I'd like a scale that reads '1,000,000' to say something link '1 mil' and '150,000' to say '150k' for the labels. Is there a way to accomplish this in ggplot2?

This code reproduces the plot idea and implements the comma format from the scales package.

library(tidyverse)
library(scales)
df <- tibble(x = LETTERS[1:10]) %>% 
  mutate(y = seq(1e3, 1e6, 
                 length.out = nrow(.)))


ggplot(df, aes(x, y))+
  geom_col()+
  scale_y_continuous(n.breaks = 10,
                     labels = dollar)

enter image description here

This has been asked/answer on SO. Please see Formatting large currency or dollar values to millions/billions

elliot
  • 1,844
  • 16
  • 45
  • 1
    This may get you started: [SI prefixes in ggplot2 axis labels](https://stackoverflow.com/questions/13973644/si-prefixes-in-ggplot2-axis-labels) – Henrik Aug 22 '20 at 17:46
  • 1
    `?scales::label_number_si`. – Axeman Aug 22 '20 at 17:48
  • No need to delete, for future ref, solved with `scale_y_continuous(labels = scales::label_number_si(prefix = "$ "))`. – Axeman Aug 22 '20 at 17:54
  • 1
    I believe it is also answered here: https://stackoverflow.com/questions/52602503/display-an-axis-value-in-millions-in-ggplot – Duck Aug 22 '20 at 17:55

0 Answers0