为数据标签添加一个逗号分隔符 [英] Include a comma separator for data labels

查看:285
本文介绍了为数据标签添加一个逗号分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 ggplot 的箱形图,它列出了数据标签,但不能在数据标签中为逗号分隔符输入1000。 sep =, aes 中似乎没有任何用处。

  ggplot(基于,aes(x = Cust = Claim.USD))+ 
geom_boxplot()+
geom_text(data = subset (标签= USD,sep =,),
hjust = 1,vjust = 1)+
scale_y_continuous(标签=逗号)


解决方案

逗号 缩放包,您需要加载该包。同样摆脱 sep ,这不是一种美学映射。这应该工作:

 库(比例)
ggplot(基于,aes(x = Cust = Claim.USD) )+
geom_boxplot()+
geom_text(data = subset(based,USD> 10000),aes(label = comma(USD)),
hjust = 1,vjust = 1)+
scale_y_continuous(labels = comma)

从您的参数名称来看,您可能更喜欢 scales :: dollar 而不是 scales :: comma


I have a box plot using ggplot which lists the data labels, but am not able to bring a comma separator for 1000s in the data label. sep ="," in aes doesn't seem to do the trick.

ggplot(based,aes(x=Cust=Claim.USD)) +
  geom_boxplot() +
  geom_text(data=subset(based,USD>10000), aes(label=USD, sep=","),
            hjust=1, vjust=1)+
  scale_y_continuous(labels=comma)

解决方案

The comma function is in the scales package, which you'll need to load. Also get rid of sep, that's not an aesthetic mapping. This should work:

library(scales)
ggplot(based,aes(x=Cust=Claim.USD)) +
  geom_boxplot() +
  geom_text(data=subset(based,USD>10000), aes(label = comma(USD)),
            hjust=1, vjust=1)+
  scale_y_continuous(labels = comma)

Judging by your argument names, you might prefer scales::dollar instead of scales::comma.

这篇关于为数据标签添加一个逗号分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆