statsguyz
statsguyz

Reputation: 469

Modifying y-axis with ggplot2

I'm trying to plot the number of observations for each instance of a word, both of which are stored in a data frame.

I can generate the plot with ggplot2, but the y-axis displays "1+e05", "2+e05",...,etc...instead of numerical values.

How can I modify this code so that the y-axis displays numbers instead?

Here is my code:

> w
p.word p.freq
1     the 294571
2     and 158624
3     you  84152
4     for  77117
5    that  71672
6    with  47987
7    this  42768
8     was  41088
9    have  39835
10    are  36458
11    but  33899
12    not  30370
13    all  27079
14   your  26923 
15   just  25507
16   from  24497
17    out  22578
18   like  22501
19   what  22150
20   will  21530
21   they  21435
22  about  21184
23    one  20877
24    its  20109

ggplot(w, aes(x = p.word, y = p.freq))+ geom_bar(stat = "identity")

Here is the plot that is generated:

enter image description here

Upvotes: 0

Views: 639

Answers (1)

mathematical.coffee
mathematical.coffee

Reputation: 56935

"1e+05" etc are numerical values (scientific notation).

If you want the long notation (e.g. "100,000") use library(scales) and the comma formatter:

library(scales)
ggplot(w, aes(x = p.word, y = p.freq))+ geom_bar(stat = "identity") +
    scale_y_continuous(labels=comma)

Upvotes: 1

Related Questions