source("getFreqDir.R")
getFreqDir("univ",tfidf=1)
dirname="univ"
filenames<-list.files(dirname)
filenames
## [1] "hiroshima.txt" "kufs.txt" "kyoto.txt" "osaka1.txt"
## [5] "osaka2.txt" "osaka3.txt" "tokyo.txt" "waseda.txt"
fname<-paste(dirname, filenames[1], sep = "/")
freqMtx<-getFreqMtx(fname)[,1:2]
freqOrder<-order(freqMtx[,2], decreasing=TRUE)
freqMtx <- freqMtx[freqOrder,]
head(freqMtx)
## term hiroshima
## 106 to 11
## 7 and 7
## 103 the 7
## 107 university 6
## 52 hiroshima 5
## 76 of 5
\[Frequency=\frac{K}{Rank^A} \] K,A: 定数
K=freqMtx[1,2]
A=0.75
rank <- seq(1:dim(freqMtx)[1])
zipf <- K/rank^A
title="Zipf's Law"
xlabel="Rank"
ylabel="Frequency"
plot(zipf, log="xy", type="l",col="red" ,
xlim=c(1,nrow(freqMtx)),ylim=c(1,20),main=title, xlab=xlabel, ylab=ylabel)
par(new=T)
plot(rank,freqMtx[,2], xlim=c(1,nrow(freqMtx)), ylim=c(1,20),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"))
library("manipulate")
title="Zipf's Law"
xlabel="Rank"
ylabel="Frequency"
A=0.75
rank <- seq(1:dim(freqMtx)[1])
manipulate(
{
zipf <- constK/rank^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,50, initial=freqMtx[1,2],step=2)
)
スライダーのステップは0.05に設定
head(tf)
## hiroshima kufs kyoto osaka1 osaka2 osaka3 tokyo waseda
## 000 0 0 0 0 0 0 0 2
## 1 0 0 0 1 0 0 0 1
## 10 0 0 1 0 0 0 0 1
## 100 0 0 0 0 1 0 0 0
## 11 2 0 0 0 0 0 0 0
## 12 1 0 0 0 0 0 0 0
library(wordcloud)
## Loading required package: RColorBrewer
wordcloud(rownames(tf),tf$hiroshima)
実行結果
wordcloud(rownames(tf),tf$osaka1,min.freq=2,colors=rainbow(10))
comparison.cloud(tf[,1:2])
comparison.cloud(tf[,4:6],max.words=60)
colnames(tf)
comparison.cloud(tf[,c(F,F,T,F,F,T,T,F)],max.words=60)
library(shiny)
shinyUI(bootstrapPage(
# Application title
headerPanel("Test Hoge"),
# Sidebar
sidebarPanel(
textInput("msg", "Please input your message:")
),
# Show a message
mainPanel(
textOutput("showMessage")
)
))
shinyServer(function(input, output) {
output$showMessage <- renderText({
input$msg
})
})
runApp("app_hoge")
runApp("app_freqBar")
#runApp("shiny_apps/app_freqBar_col")
alt text
alt text