【发布时间】:2021-04-30 21:43:50
【问题描述】:
我正在尝试在直方图上添加数据标签,但希望看到有限的小数。当前代码如下:
label = after_stat(scales::percent(cumsum((count / sum(count))))))
它工作正常,但根据绘制的图表变量数据返回不同的小数位数。
然后我引用了这个链接: how to put exact number of decimal places on label ggplot bar chart 修改代码如下:
label = after_stat(sprintf("%0.f",round(scales::percent(cumsum((count / sum(count)))),digits=2)))
轮次错误(scales::percent(cumsum((count/sum(count))))): 数学函数的非数字参数
您能否建议正确的方法来修剪/舍入小数点以表示 2 位?谢谢。
【问题讨论】: