Data Science Desktop Survival Guide
by Graham Williams |
|||||
Labels with Comma |
20200428
ds %>%
ggplot(aes(wind_dir_9am, fill=wind_dir_9am)) + geom_bar() + scale_y_continuous(labels=comma) + theme(legend.position="none") + labs(x=vnames["wind_dir_9am"], y="Count")
With ggplot2 Version 0.9.0 the scales package introduced a mechanism to handle many of the scale operations, in such a way as to support base and lattice graphics, as well as ggplot2 graphics. Scale operations include position guides, as in the axes, and aesthetic guides, as in the legend. The function scales::comma() is useful for presenting numbers using commas to separate the thousands. This is always a good idea as it assists the reader in quickly determining the magnitude of the numbers we are looking at. As a matter of course, I recommend commas in plots (and tables) at all times. To do so use scale_y_continuous() with labels=comma.
|