Euro symbol in ggplot: package of weights

I have noticed that using a package scales, you can display the dollars on the axis, using the parameter scales = dollarin, for example scale_y_log10(). It seems that there is no such option as scales = euro. Is there an easy way to achieve the same effect?

+5
source share
2 answers

It is easy to change the value of the dollar and change the symbol to euro. Run this and put it in code, as you would calldollar_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))
  }
}
+12
source

You can use arguments prefixandsuffix dollar_format

For example, for example:

library(ggplot2)
library(scales)       
ggplot(diamonds) + geom_point(aes(x = carat, y =  price)) + scale_y_continuous(labels = dollar_format(suffix = "€", prefix = ""))
+6
source

All Articles