为数据标签添加一个逗号分隔符

编程入门 行业动态 更新时间:2024-10-25 08:28:14
本文介绍了为数据标签添加一个逗号分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个使用 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.

更多推荐

为数据标签添加一个逗号分隔符

本文发布于:2023-10-16 10:22:49,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:逗号   标签   分隔符   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!