【发布时间】:2018-01-02 21:18:53
【问题描述】:
我正在尝试更改 ggplot 上数据标签中数字的格式(改为逗号),但找不到答案。希望你能帮忙:)
示例如下:
library("scales")
library("tidyverse")
df = tibble(year = as.factor(c(2016,2016,2017,2017)),
kpi = c("value", "volume","value", "volume"),
values = c(99999,8888,111111,11000))
df %>%
ggplot()+
aes(year,values, fill = kpi) +
geom_col() +
scale_y_continuous(labels = comma) +
stat_summary(fun.y = sum,
aes(label = ..y..,
group = year),
geom = "text",
vjust = 1,
size =3) +
labs(title = "KPI By Year",
fill = "KPIs",
y = NULL,x = "Year")+
theme(legend.position="bottom")+
facet_wrap(~kpi, scales = "free_y", ncol = 1)
这就是我得到的。用逗号格式化对可读性有很大帮助。
【问题讨论】:
-
您是在问如何添加千位分隔符吗? (标签=逗号)
-
如果有,可能是重复的:stackoverflow.com/questions/32427639/…