[R] ggplot2 axis label German formatting

Ista Zahn istazahn at gmail.com
Sun Jan 12 19:36:29 CET 2014


Hi,

You can write a function to format the labels, like this:

gcomma <- function(x) format(x, ..., big.mark = ".", decimal.mark =
",", scientific = FALSE)

p.new + scale_x_continuous(labels = gcomma)

Best,
Ista

On Sun, Jan 12, 2014 at 6:02 AM, Stageexp <ronjaq at gmx.net> wrote:
> Hi all I have a problem with formatting my ggplot2 graph.
>
> Let's look at this example:
> library(ggplot2)
> library(scales)
> x <- rnorm(100, mean=100, sd = 1) * 1000000
> y <- rnorm(100, mean=100, sd = 1) * 1000000
> df <- data.frame(x,y)
>
> p.new <- ggplot(df,aes(x,y)) +
>   geom_point()
> print(p.new)
>
> This is showing the axis labels in scientific notation. Adding
>
> p.new + scale_x_continuous(labels = comma)
>
> will show the numbers correctly, BUT: In Germany, we use decimal points and
> commas exactly the other way around, for example, we write 5,3% and 100.000.
>
> I only found the options "comma", "dollar" and "percent" for labels. Is
> there any way in which I can show the numbers separated by decimal points?
>
>
> Kind Regards
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/ggplot2-axis-label-German-formatting-tp4683477.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list