如何在标记条形图时将 geom_text 更改为货币?
How do I change the geom_text to currency when it is labeling a bar graph?
我有一个条形图,每个条形图的顶部都有标签来显示数量。
如何将其更改为货币格式?
这是一个例子:
df <- tribble(~county, ~amount,
"A", 200000,
"B", 1000000,
"C", 500000,
"D", 250000)
df %>%
ggplot(aes(x = county, y = amount)) +
geom_col() +
scale_y_continuous(labels = label_dollar()) +
geom_text(aes(label = amount), vjust = -.5)
使用label_dollar()(..)
:
df <- tribble(~county, ~amount,
"A", 200000,
"B", 1000000,
"C", 500000,
"D", 250000)
df %>%
ggplot(aes(x = county, y = amount)) +
geom_col() +
scale_y_continuous(labels = label_dollar()) +
geom_text(aes(label = label_dollar()(amount)), vjust = -.5)
我有一个条形图,每个条形图的顶部都有标签来显示数量。
如何将其更改为货币格式?
这是一个例子:
df <- tribble(~county, ~amount,
"A", 200000,
"B", 1000000,
"C", 500000,
"D", 250000)
df %>%
ggplot(aes(x = county, y = amount)) +
geom_col() +
scale_y_continuous(labels = label_dollar()) +
geom_text(aes(label = amount), vjust = -.5)
使用label_dollar()(..)
:
df <- tribble(~county, ~amount,
"A", 200000,
"B", 1000000,
"C", 500000,
"D", 250000)
df %>%
ggplot(aes(x = county, y = amount)) +
geom_col() +
scale_y_continuous(labels = label_dollar()) +
geom_text(aes(label = label_dollar()(amount)), vjust = -.5)