1

Is there a way to display labels as

0.01, 0.1, 1, 10, 100 

instead of

0.01, 0.10, 1.00, 10.00, 100.00

i.e., truncating trailing zeros after the decimal?

x <- c(0.01, 0.1, 1, 10, 100)
scales::demo_log10(x)
scales::demo_log10(x, labels = scales::label_number())
Mikael Jagan
  • 9,012
  • 2
  • 17
  • 48
  • Please provide enough code so others can better understand or reproduce the problem. – Community Mar 08 '23 at 21:34
  • Does this answer your question? [How do I change the number of decimal places on axis labels in ggplot2?](https://stackoverflow.com/questions/38722202/how-do-i-change-the-number-of-decimal-places-on-axis-labels-in-ggplot2) – Michael Roswell Mar 09 '23 at 16:31

1 Answers1

1

The label_number() function forwards the ... argument to the format() function. This mean that you use its drop0trailing argument to control whether 0s are printed after the decimal mark.

library(scales)
demo_log10(
  c(0.01, 0.1, 1, 10, 100),
  labels = label_number(drop0trailing = TRUE)
)
#> scale_x_log10(labels = label_number(drop0trailing = TRUE))
PatPanda
  • 3,644
  • 9
  • 58
  • 154