我想在我的条形图中添加“M”或“K”后缀。每个标签的数字显示完整的原始数字,但我想四舍五入到最接近的千位并显示后缀“K”或“M”。不幸的是,我尝试了上面的解决方案,但它不起作用。我尝试了这个解决方案:
geom_text(aes(label=label_number(scale=1e-3, suffix='K')))
但它在我的代码中无法正常工作。请帮我解决一下吗?
db %>%
ggplot(aes(x = reorder(name, totalEarnings), y = totalEarnings, fill = totalEarnings)) +
geom_bar(stat = "identity", show.legend = FALSE) +
coord_flip() +
theme(plot.background = element_blank(),
panel.background = element_blank(),
axis.title = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_text(colour = "black")) +
geom_text(aes(label = totalEarnings), size = 3, hjust = -0.1, color = "black", fontface = "bold")
尝试
label_number(scale_cut = cut_short_scale())
。