I've noticed that, using the scales package, one can display dollars on an axis, using the scales = dollar option inside, for instance, scale_y_log10(). An option like scales = euro seems to be lacking. Is there an easy way for me to achieve the same effect?
You can use the prefix and suffix arguments of dollar_format
For example like this:
library(ggplot2)
library(scales)
ggplot(diamonds) + geom_point(aes(x = carat, y = price)) +
scale_y_continuous(labels = dollar_format(suffix = "€", prefix = ""))
It's easy to modify dollar_format and change the symbol to euro. Run this and put it in the code like you would call dollar_format
euro_format <- function(largest_with_cents = 100000) {
function(x) {
x <- round_any(x, 0.01)
if (max(x, na.rm = TRUE) < largest_with_cents &
!all(x == floor(x), na.rm = TRUE)) {
nsmall <- 2L
} else {
x <- round_any(x, 1)
nsmall <- 0L
}
str_c("€", format(x, nsmall = nsmall, trim = TRUE, big.mark = ",", scientific = FALSE, digits=1L))
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With