【发布时间】:2019-12-18 16:46:17
【问题描述】:
我需要有固定的小数位数(在这种情况下是两个),但我无法让它工作,
我知道使用 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)
【问题讨论】:
-
一个相当奇怪的“黑客”:
geom_text(aes(label=paste0(round(..count../sum(..count..) ,4) * 100,"%")), stat='count',vjust = -0.5, size = 4)