这是几天前开始发生的,该scales::percent
将在其标签中添加一个小数位,而且我似乎无法禁用该小数位以在y轴上显示整数值。
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)
最佳答案
也许不是您问题的直接答案,但是我在相似的设置中使用了scales::percent_format
及其accuracy
参数(“要舍入的数字”)。
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))
我认为
percent
的行为已在scales 1.0.0
中更改。请参见NEWS和代码here中的更新。
关于r - 如何防止小数位数::百分比加小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53072282/