我有一個頻率和維基百科語料庫處理的單詞排名。只需要一行x(單詞等級)和y(頻率)數字,並且需要R中的對數圖表,如下所示:http://en.wikipedia.org/wiki/File:Wikipedia-n-zipf.png如何產生對數秩/頻率圖?
我該怎麼做?我不斷變換或不正確的版本。謝謝。
我有一個頻率和維基百科語料庫處理的單詞排名。只需要一行x(單詞等級)和y(頻率)數字,並且需要R中的對數圖表,如下所示:http://en.wikipedia.org/wiki/File:Wikipedia-n-zipf.png如何產生對數秩/頻率圖?
我該怎麼做?我不斷變換或不正確的版本。謝謝。
只需基本功能:
plot(x, y, log="xy")
這將繪製在對數刻度您的觀點。
隨着lattice
和latticeExtra
:
library(lattice)
library(latticeExtra)
xyplot((1:200)/20 ~ (1:200)/20, type = c('p', 'g'),
scales = list(x = list(log = 10), y = list(log = 10)),
xscale.components=xscale.components.log10ticks,
yscale.components=yscale.components.log10ticks)
更多實例here。
你已經通過獲得單詞的頻率和等級來努力工作。你只需要在日誌範圍內繪製它們。
##Word frequencies in Moby dick
dd = read.csv("http://tuvalu.santafe.edu/~aaronc/powerlaws/data/words.txt")
##Rename the columns and add in the rank
colnames(dd) = "freq"
dd$rank = 1:nrow(dd)
##Plot using base graphics
plot(dd$rank, dd$freq, log="xy")
或者你可以使用ggplot2
require(ggplot2)
ggplot(data=dd, aes(x=rank, y=Freq)) +
geom_point() + scale_x_log10() +
scale_y_log10()