我需要固定数量的小数(在本例中是两个),我无法使它工作,我知道使用round和accuracy函数,但它似乎对我不起作用。
代码:
library(ggplot2)
ggplot(mtcars, aes(factor(cyl))) +
geom_bar(color = "steelblue", fill = "#00AFBB", na.rm = T) +
scale_fill_discrete(drop=FALSE) +
scale_x_discrete(drop=FALSE) +
geom_text(aes(label=scales::percent(round(..count../sum(..count..),4))),
stat='count',vjust = -0.5, size = 4)发布于 2019-12-18 16:56:30
这是内置到scales::percent的。有一个accuracy参数,它被描述为“要舍入的数字”。
ggplot(mtcars, aes(factor(cyl))) +
geom_bar(color = "steelblue", fill = "#00AFBB", na.rm = T) +
scale_fill_discrete(drop=FALSE) +
scale_x_discrete(drop=FALSE) +
geom_text(aes(label=scales::percent(..count../sum(..count..), accuracy = 0.01)),
stat='count',vjust = -0.5, size = 4)https://stackoverflow.com/questions/59396655
复制相似问题