r ggplot with zeroes and no comma as the big number separator

user3357059

I am trying to count instances by month, plot them on a graph and adding monthly counts to the top of the bars as labels. Below is a reproducible example of the problem I have:

library(scales)
library(ggplot2)

set.seed(1)

df <- data.frame(DueDate = as.Date(paste("2015", 
sample(1:6, 6000, replace=T), 
sample(1:30, 6000, replace=T), sep = "-")),
stringsAsFactors = F)

ggplot(df, aes(as.Date(cut(DueDate,
  breaks = "month")) )) + 
  geom_bar() +
  geom_text(stat = 'bin', 
            aes(label = ..count..),
            vjust = -1, 
            size = 2) +
  scale_y_continuous(labels = comma) +
 labs(x = "Month", y = "Frequency") + 
  theme_minimal()

The issue is that when I create the plot there are 0s between the bars and the numbers on top of the bars do not have commas as the big number separator.

enter image description here

IRTFM

Corrected a couple of errors that were in my comments above. Sampling from a Date-sequence lets you count the 31st days of the month and avoid the NA's from the 29-30th nondays in Feb.

set.seed(1)

df <- data.frame(DueDate = format(
         sample( 
             seq( as.Date("2015-01-01"), 
                  as.Date("2015-06-30"), by="1 day") ,  
             6000,replace=T),     "%b"),
                 stringsAsFactors = F)
    #  This does all the aggregation in one step.
    #  Could probably leave them as Dates and use `format` in the `aes` call
ggplot(df, aes(DueDate)) + 
  geom_bar() +
  geom_text(stat = 'bin', 
            aes(label = formatC(..count.., big.mark=",") ),
            vjust = -1, 
            size = 2) +
  scale_y_continuous(labels = comma) +
 labs(x = "Month", y = "Frequency") + 
  theme_minimal()

Multiplied sample size by two to show that the comma-argument to the y-scale was working.

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How do I change the decimal separator in r-exams question to comma?

From Java

Add leading zeroes to number in Java?

From Dev

Python regex for number with or without decimals using a dot or comma as separator?

From Dev

Jaxb conversion of number with comma as a decimal separator

From Dev

Log axis labels in ggplot2: full number without comma?

From Dev

How to format numbers in R, specifying the number of significant digits but keep significant zeroes and integer part?

From Dev

jQuery Validation Plugin: validate decimal number with comma as decimal separator

From Dev

Add comma separator to axis labels

From Dev

Change the thousands separator in a ggplot

From Dev

seq uses comma as decimal separator

From Dev

R / Excel : leading zeroes

From Dev

Masked EditText with comma as decimal separator

From Dev

Format number in R with both comma thousands separator and specified decimals

From Dev

include comma separator in javascript for loop

From Dev

Include a comma separator for data labels

From Dev

Add leading zeroes to number in Dart

From Dev

Is comma (,) operator or separator in Java?

From Dev

Is comma (,) operator or separator in Java?

From Dev

dot instead of comma as thousand separator

From Dev

Log axis labels in ggplot2: full number without comma?

From Dev

How to make a efficient comma separator

From Dev

R - ggplot2 - boxplots are too big

From Dev

Space separator INSTEAD of a comma - large number outputs

From Dev

comma separator using implode not working

From Dev

ggplot figure number in for loop in R

From Dev

formatting decimal number to string with comma as decimal separator in racket

From Dev

Number of consecutive zeroes in a list

From Dev

Comma after leading zeroes

From Dev

Maintaining long number string in R, avoiding scientific notation and not deleting leading zeroes

Related Related

  1. 1

    How do I change the decimal separator in r-exams question to comma?

  2. 2

    Add leading zeroes to number in Java?

  3. 3

    Python regex for number with or without decimals using a dot or comma as separator?

  4. 4

    Jaxb conversion of number with comma as a decimal separator

  5. 5

    Log axis labels in ggplot2: full number without comma?

  6. 6

    How to format numbers in R, specifying the number of significant digits but keep significant zeroes and integer part?

  7. 7

    jQuery Validation Plugin: validate decimal number with comma as decimal separator

  8. 8

    Add comma separator to axis labels

  9. 9

    Change the thousands separator in a ggplot

  10. 10

    seq uses comma as decimal separator

  11. 11

    R / Excel : leading zeroes

  12. 12

    Masked EditText with comma as decimal separator

  13. 13

    Format number in R with both comma thousands separator and specified decimals

  14. 14

    include comma separator in javascript for loop

  15. 15

    Include a comma separator for data labels

  16. 16

    Add leading zeroes to number in Dart

  17. 17

    Is comma (,) operator or separator in Java?

  18. 18

    Is comma (,) operator or separator in Java?

  19. 19

    dot instead of comma as thousand separator

  20. 20

    Log axis labels in ggplot2: full number without comma?

  21. 21

    How to make a efficient comma separator

  22. 22

    R - ggplot2 - boxplots are too big

  23. 23

    Space separator INSTEAD of a comma - large number outputs

  24. 24

    comma separator using implode not working

  25. 25

    ggplot figure number in for loop in R

  26. 26

    formatting decimal number to string with comma as decimal separator in racket

  27. 27

    Number of consecutive zeroes in a list

  28. 28

    Comma after leading zeroes

  29. 29

    Maintaining long number string in R, avoiding scientific notation and not deleting leading zeroes

HotTag

Archive