5

I use sitools to format the tick labels on my ggplot2 charts. When I deal with large numbers, the largest major tick label ends up being "NANA" and a warning message is displayed in the console:

Warning message:
  In number/sifactor[ix] :
  longer object length is not a multiple of shorter object length

enter image description here

library(ggplot2)
library(sitools)

data <- data.frame(list(
 Quarter=as.factor(c("Q1 2015","Q2 2015","Q3 2015","Q4 2015","Q1 2016")),
 Operations=c(23000000,54000000,120000000,450000000,12000000)
))

line_chart <- function(df, x, y, tit, xtit, ytit) {
  return(
    df %>% ggplot(aes_string(x=x, y=y)) +
      geom_bar(stat = "identity", size=1) +
      xlab(xtit) +
      ylab(ytit) +
      scale_y_continuous(labels = f2si) +
      ggtitle(tit)
  )
}

line_chart(df=data,
           x="Quarter",y="Operations",
           tit="OPERATIONS BY QUARTER",
           xtit="QUARTER", ytit="OPERATIONS")

Thanks a lot

xav
  • 4,101
  • 5
  • 26
  • 32
  • These posts could help you (if you did not see them): (http://stackoverflow.com/questions/21045545/how-to-accurately-display-si-prefix-for-numbers-in-y-axis-scale-of-plot-made-wit) (http://stackoverflow.com/questions/13973644/si-prefixes-in-ggplot2-axis-labels) – bVa Apr 25 '16 at 12:56
  • Thanks, the first one actually shows how to avoid the problem (without solving it :) ) – xav Apr 25 '16 at 14:20

0 Answers0