'avoid scientific notation x axis ggplot

This:

ggplot(Data, aes(x = Bla), bins = 30, labels = TRUE, format(x, scientific = FALSE)) +
    geom_histogram()

does not work. I want to suppress the scientific notation (e.g. 1.0e+07). Any ideas? Thanks!

r


Solution 1:[1]

There are a couple of options apart from options(scipen = 999) which you may want to avoid if you don't want set this for all charts.

ggplot(Data, aes(x = Bla), bins = 30) +
  geom_histogram() +
  scale_x_continuous(labels = ~ format(.x, scientific = FALSE))

or

ggplot(Data, aes(x = Bla), bins = 30) +
  geom_histogram() +
  scale_x_continuous(labels = scales::comma)

Instead of scales::comma, the scales packages also offers

  • scales::label_number()
  • scales::label_dollar()
  • scales::label_date()

which are handy if you have financial data or dates.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Agile Bean