source("getRelativeFreqMtx.R")
freqMtx<-getRelativeFreqMtx("osaka-u.txt")
subMtx <-as.table(freqMtx[1:20,2])
names(subMtx) <-freqMtx[1:20,]$term
library(manipulate)
manipulate({
plot(0,0,type="n")
text(0,0, "MINO",cex=mySize,col=myColors)
},
myColors=picker("red", "yellow", "green", "violet", "orange", "blue", "pink", "cyan"),
mySize=slider(1,10,initial=3))
title="Word Frequency Distribution"
xlabel="Word"
ylabel="Frequency"
manipulate(barplot(subMtx,col=myColors,main=title, xlab=xlabel, ylab=ylabel,las=3), myColors=picker("red", "yellow", "green", "violet", "orange", "blue", "pink", "cyan" ,initial="pink") )
manipulate(barplot(subMtx,col=myColors,main=title, xlab=xlabel, ylab=ylabel, xlim=c(0,x.max),las=3), myColors=picker("red", "yellow", "green", "violet", "orange", "blue", "pink", "cyan",initial="pink") , x.max=slider(1,20, initial=10))
manipulate(barplot(subMtx,col=myColors,main=title, xlab=xlabel, ylab=ylabel, xlim=c(x.min,x.max),las=3), myColors=picker("red", "yellow", "green", "violet", "orange", "blue", "pink", "cyan",initial="pink") , x.min=slider(1,10, initial=1),x.max=slider(11,20, initial=20))
freqMtx$term[1]
## [1] the
## 246 Levels: 18th 1931 2003 2007 a ability academic accepted ... your
as.character(freqMtx$term[1])
## [1] "the"
nchar(as.character(freqMtx$term[1]))
## [1] 3
ncharAll <- nchar(as.character(freqMtx$term))
charlenF
## ncharAll
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14
## 4 14 19 34 33 25 30 27 28 13 11 3 4 1
title="Word Length Frequency Distribution (Types)"
xlabel="Word Length"
ylabel="Frequency"
xmax=length(charlenF)
ymax=max(charlenF)
plot(charlenF, type="b",pch=8,col="orange",xlim=c(1,xmax),ylim=c(1,ymax),main=title, xlab=xlabel, ylab=ylabel)
title="Word Frequency Distribution"
xlabel="Rank"
ylabel="Frequency"
rank=seq(1:dim(freqMtx)[1])
plot(rank,freqMtx[,2], pch=8, col="darkgreen", main=title, xlab=xlabel, ylab=ylabel)
plot(rank,freqMtx$raw, xlim=c(1,nrow(freqMtx)), ylim=c(1,50),log="xy",pch=8, col="darkgreen", main=title, xlab=xlabel, ylab=ylabel)
\[Frequency=\frac{K}{Rank^A} \] K,A: 定数
K=freqMtx[1,2]
A=0.75
rank <- seq(1:dim(freqMtx)[1])
zipf <- unlist(lapply(rank, function(r) K/r^A))
## [1] 33.000000 19.621917 14.476814 11.667262 9.869302 8.607965 7.668147
## [8] 6.937395 6.350853 5.868322
title="Zipf's Law"
xlabel="Rank"
ylabel="Frequency"
plot(zipf, log="xy", type="l",col="red" ,
xlim=c(1,nrow(freqMtx)),ylim=c(1,50),main=title, xlab=xlabel, ylab=ylabel)
par(new=T)
plot(rank,freqMtx[,2], xlim=c(1,nrow(freqMtx)), ylim=c(1,50),log="xy",pch=8, col="darkgreen", main=title, xlab=xlabel, ylab=ylabel)
配置:“bottomright”, “bottom”, “bottomleft”, “left”, “topleft”, “top”, “topright”, “right”, “center” ラベル lty: 線の種類 pch: プロットの種類
legend("topright",c("Frequency","Zipf's law"),lty=c(NA,1),pch=c(8,NA),col=c("darkgreen","red"))
picker()関数
alt text
title="Zipf's Law"
xlabel="Rank"
ylabel="Frequency"
K=res[1,2]
A=0.75
K
rank <- seq(1:dim(freqMtx)[1])
manipulate(
{
zipf <- unlist(lapply(rank, function(r) constK/r^A))
plot(zipf, log="xy", type="l",col="red" ,
xlim=c(1,nrow(freqMtx)),ylim=c(1,50),main=title, xlab=xlabel, ylab=ylabel)
par(new=T)
plot(rank,freqMtx[,2], xlim=c(1,nrow(freqMtx)), ylim=c(1,50),log="xy",pch=8, col="darkgreen", main=title, xlab=xlabel, ylab=ylabel)
legend("topright",c("Frequency","Zipf's law"),lty=c(NA,1),pch=c(8,NA),col=c(col="darkgreen",col="red"))
text(20, 50, "Frequency=K/Rank^A")
text(20, 40, paste("K=", constK))
text(20, 30, paste("A=", A))
}
, constK=slider(10,100, initial=freqMtx[1,2],step=2)
)
スライダーのステップは0.05に設定
alt text