25

This started happening a few days ago, that scales::percent would add a decimal place in its labels, and I can't seem to disable this decimal to display integer values on y-axis. enter image description here

library(dplyr)
library(ggplot2)

mtcars %>% 
  count(cyl) %>% 
  mutate(prop = n / sum(n)) %>% 
  ggplot(aes(x = cyl, y = prop)) + 
  geom_point() + 
  scale_y_continuous(labels = scales::percent)
Henrik
  • 65,555
  • 14
  • 143
  • 159
Joe
  • 3,217
  • 3
  • 21
  • 37

2 Answers2

27

Perhaps not a direct answer to your question, but I have used scales::percent_format and its accuracy argument ("Number to round to") in similar settings.

mtcars %>% 
    count(cyl) %>% 
    mutate(prop = n / sum(n)) %>% 
    ggplot(aes(x = cyl, y = prop)) + 
    geom_point() + 
    scale_y_continuous(labels = scales::percent_format(accuracy = 5L))

enter image description here


I think the behaviour of percent was changed in scales 1.0.0. See NEWS and updates in code here.

Community
  • 1
  • 1
Henrik
  • 65,555
  • 14
  • 143
  • 159
18

Just an update, scales::label_percent(accuracy = 1L) will round to the whole number, scales::label_percent(accuracy = 0.1L) will round to the first decimal and so on.

landrower
  • 475
  • 6
  • 11