简体   繁体   中英

Include a comma separator for data labels

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM