Skip to content

Instantly share code, notes, and snippets.

@strongh
Created September 15, 2010 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strongh/580220 to your computer and use it in GitHub Desktop.
Save strongh/580220 to your computer and use it in GitHub Desktop.
dollar-log formatting example
## Homer Strong, September 2010
##
## This is an example of using dollar formatting with log10 scaling.
## See the commit
## http://github.com/strongh/ggplot2/commit/7402a13a8ad625a8acd3024c5726545a20ac838e
library(ggplot2)
data(diamonds)
## On the current ggplot, the formatter argument is ignored when using
## either scale_*_<trans>() or scale_*_continous(trans='<trans>').
## I wanted to use the log10 trans but keep the 'dollar' formatting, as with
ggplot(diamonds, aes(price)) + geom_histogram() + scale_x_continuous(trans='log10', formatter='dollar')
## The x-axis labels are formatted now as '$10^4' (with the superscript properly raised), as
## opposed to '10^4'. Even if there is another way to accomplish this, I feel like it's a
## consistent use of the formatting options.
##
## By the way, the plot above can be found in the downloads section of my ggplot2 fork,
## http://github.com/strongh/ggplot2/downloads
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment