使用 ggplot2 修改 y 轴

Modifying y-axis with ggplot2

我正在尝试绘制每个单词实例的观察次数,这两个实例都存储在数据框中。

我可以用 ggplot2 生成绘图,但 y 轴显示“1+e05”、“2+e05”...等...而不是数值。

如何修改此代码,使 y 轴显示数字?

这是我的代码:

> 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")

这是生成的图:

“1e+05”等数值(科学计数法)。

如果您想要长符号(例如“100,000”),请使用 library(scales)comma 格式化程序:

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