如何防止小数位数::百分比加小数 [英] How to prevent scales::percent from adding decimal
本文介绍了如何防止小数位数::百分比加小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是几天前开始的事情,scales::percent
将在其标签中添加一个小数位,而且我似乎无法禁用该小数位以在y轴上显示整数值.
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.
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
参数(要舍入的数字")设置.
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))
我认为percent
的行为在scales 1.0.0
中已更改.参见新闻和代码中的更新
I think the behaviour of percent
was changed in scales 1.0.0
. See NEWS and updates in code here.
这篇关于如何防止小数位数::百分比加小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文