Enable comma delimiter for data labels

I have a graph using ggplotthat lists data labels, but I can't cast a comma separator for the 1000s to a data label. sep =","in aesdoes not seem to perform 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)
+4
source share
1 answer

The function commais in the package scalesyou need to download. Also get rid of sepwhat is not an aesthetic display. 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::dollarinstead scales::comma.

+5
source

Source: https://habr.com/ru/post/1606176/


All Articles