Monday, June 4, 2012

axis tick labels with comma as decimal point (german style)

german commas - commas as decimal point

  • how to format the axis tick label, as example we use formatting numbers in german style (comma as dec)
  • first we have to write a little function using the format function from the base package (which makes it very easy)
## the formatter function
germ_commas <- function(x,...){
  format(x, dec="," , trim = TRUE, scientific = FALSE, ...)
}

## create example data
x <- y <- rnorm(10)
z <- data.frame(x=x,y=y)

## create the plot using the function above inside the scales
ggplot(z,aes(x=x,y=y)) +
  geom_point() +
  scale_x_continuous(labels=germ_commas,breaks=seq(-2.5,2.5,by=0.25)) +
  scale_y_continuous(labels=germ_commas,breaks=seq(-2.5,2.5,by=0.25)) +
  opts(axis.text.x = theme_text(size=13,angle=90)) +
  opts(axis.text.y = theme_text(size=13))

0 comments:

Post a Comment