R 如何生成对数秩/频率图?
我有维基百科语料库中经过处理的单词的频率和等级。只需要一行x(词组)和y(频率)数字,并希望在R中绘制如下所示的对数图:R 如何生成对数秩/频率图?,r,graph,logging,R,Graph,Logging,我有维基百科语料库中经过处理的单词的频率和等级。只需要一行x(词组)和y(频率)数字,并希望在R中绘制如下所示的对数图: 我该怎么做?我不断得到相反或不正确的版本。谢谢。与晶格和晶格额外: 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)),
我该怎么做?我不断得到相反或不正确的版本。谢谢。与
晶格
和晶格额外
:
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)
更多示例。通过获取单词的频率和等级,您已经完成了艰苦的工作。你只需要在对数刻度上绘制它们
##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()
仅使用基本功能:
plot(x, y, log="xy")
这将在对数刻度上绘制点