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)
This has been asked/answer on SO. Please see Formatting large currency or dollar values to millions/billions