Format barchart labels with commas in numbers?

3,256 views
Skip to first unread message

Sharon Machlis

unread,
Nov 9, 2015, 12:09:17 PM11/9/15
to ggplot2
If I am labeling bars in a ggplot2 barchart so label values show up, adding 

geom_text(aes(label=myycolname), vjust=1.5, colour="white", position=position_dodge(.9), size=5)

as demonstrated in the R Graphics Cookbook, is there a way to format the label numbers to show commas? My usual number-formatting option formatC won't work directly on myycol. Thanks.

Doug Mitarotonda

unread,
Nov 9, 2015, 12:19:05 PM11/9/15
to Sharon Machlis, ggplot2
See the `comma` function in the `scales` package, so you can use `label = comma(myycolname)`. You might find it’s `dollar` and `percent` functions useful in other use cases.

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sharon Machlis

unread,
Nov 9, 2015, 10:02:53 PM11/9/15
to ggplot2, smac...@gmail.com
Yes, that did the trick, thanks!
Reply all
Reply to author
Forward
0 new messages