【问题标题】:Can't plot Zipf's law in R无法在 R 中绘制 Zipf 定律
【发布时间】:2015-04-07 11:08:01
【问题描述】:

我有一个从文本文件加载的术语及其频率的大列表,我将其转换为表格:

myTbl = read.table("word_count.txt")  # read text file 

colnames(myTbl)<-c("term", "frequency")
head(myTbl, n = 10)

> head(myTbl, n = 10)
    term frequency
1     de     35945
2      i     34850
3  \xe3n     19936
4      s     15348
5     cu     13722
6     la     13505
7     se     13364
8     pe     13361
9     nu     12693
10     o     11995

我可能应该添加一个带有单词排名的列,然后根据频率绘制排名,但是我该怎么做呢?

【问题讨论】:

    标签: r distribution tm qdap


    【解决方案1】:

    与其自行计算,不如使用tm 包更容易。将 myTbl 转换为术语文档矩阵 (tdm)

    library(tm)
    tdm <- TermDocumentMatrix(myTbl) # there are many more clean up steps, but I am simplifying 
    

    那么你不仅有 Zipf,还有要显示的堆和绘图。

    Zipf_plot(tdm) 
    Heaps_plot(tdm) # how vocabulary grows as size of text grows
    

    或者,您可以使用qdap 包及其排名频率图。这是小插曲的引述:

    排名频率图是一种可视化单词排名与 与 Zipf 定律相关的频率,该定律指出 词与其频率成反比。 rank_freq_mplot 和 rank_freq_plot 提供了绘制等级和频率的方法 单词(通过分组变量绘制 rank_freq_mplot)。
    Rank_freq_mplot 使用 ggplot2 包,而 rank_freq_plot 使用基本图形。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多