hadley/scales — Issue #12: dollar_format and missing data
Author: ifellows
Created: 2012-02-21 08:42:36+00:00
State: open

> ggplot() +
+ geom_point(aes(x = carat,y = price),data=diamonds) +
+ scale_y_continuous(labels = dollar_format())
Error in if (max(x) < 100) 2 else 0 :
missing value where TRUE/FALSE needed

solution:

dollar_format <- function ()
{
function(x) {
x <- round_any(x, 0.01)
nsmall <- if (max(x, na.rm=TRUE) < 100)
2
else 0
str_c("$", format(x, nsmall = nsmall, trim = TRUE, big.mark = ","))
}
}