如何生成对数日志等级/频率图?

时间:2011-10-18 09:24:00

标签: r graph logging

我有来自维基百科语料库的单词的频率和排名。只需一行x(单词排名)和y(频率)数字,并希望R中的对数日志图如下所示:http://en.wikipedia.org/wiki/File:Wikipedia-n-zipf.png

我该怎么做?我一直在反转或不正确的版本。感谢。

3 个答案:

答案 0 :(得分:2)

仅使用基本功能:

plot(x, y, log="xy") 

这将在对数刻度上绘制您的点。

答案 1 :(得分:1)

latticelatticeExtra

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

答案 2 :(得分:1)

通过获得单词的频率和排名,你已经完成了艰苦的工作。您只需要在对数刻度上绘制它们。

##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()
相关问题