How to change the format on data labels with ggplot

by Marek   Last Updated January 02, 2018 21:26 PM

I am trying to change the format of the numbers in data labels (to comma) on the ggplot, but can not find the answer. Hop you can help :)

Here is the example:

library("scales")
library("tidyverse")
df = tibble(year = as.factor(c(2016,2016,2017,2017)),
        kpi = c("value", "volume","value", "volume"),
        values = c(99999,8888,111111,11000)) 
df %>%
ggplot()+
aes(year,values, fill = kpi) +
geom_col() +
scale_y_continuous(labels = comma) +
stat_summary(fun.y = sum,
           aes(label = ..y..,
               group = year),
           geom = "text",
           vjust = 1,
           size =3) +
labs(title = "KPI By Year",
     fill = "KPIs",
     y = NULL,x = "Year")+
theme(legend.position="bottom")+
facet_wrap(~kpi, scales = "free_y", ncol = 1)

And this is what I get. Formatting with comma would help a lot with readability.

enter image description here

Tags : r ggplot2


Related Questions


R - How to find points within specific Contour

Updated May 28, 2015 23:11 PM

How to see the code of a stored plot (ggplot)

Updated May 29, 2015 01:11 AM

R ggplot remove certain items from legend

Updated April 03, 2015 23:11 PM

add second axis label

Updated April 10, 2015 23:11 PM

Error in facet_grid in ggplot2

Updated October 09, 2016 09:11 AM