library(manipulate)
library(wordcloud)
## Loading required package: RColorBrewer
source("getFreqMtx.R")
freqMtx<-getFreqMtx("Lec04-text.txt")
freqMtx<-freqMtx[order(freqMtx$raw, decreasing = TRUE),]
tmp <- freqMtx[1:20,1]
names(tmp) <-rownames(freqMtx)[1:20]
manipulate(
barplot(tmp,las=myLas,col=myColors),
myLas=picker(1,2,3, initial =3),
myColors=picker("red", "violet", "pink", "orange", "yellow", "green", "blue", "cyan", initial ="green")
)
genWC <- function(words, freq, colorFlag=0){
if(colorFlag==0){
wordcloud(words,freq)
}else{
wordcloud(words,freq,colors=rainbow(10))
}
}
Top20<- freqMtx[1:20,]
genWC(rownames(Top20),Top20$raw)
genWC(rownames(Top20),Top20$raw, colorFlag=1)
tmp <- freqMtx[1:20,1]
names(tmp) <-rownames(freqMtx)[1:20]
barplot(tmp,las=3)
manipulate(
plot(0,0,pch=myMarkers,cex=5,col=myColors), myColors=picker("red", "violet", "pink", "orange", "yellow", "green", "blue", "cyan",initial="violet"),
myMarkers=picker(1,2,3,4,5,6,7,8,initial="5")
)
manipulate(
plot(0,0,pch=8,cex=mySize,col="blue"),
mySize=slider(1,10,initial=5)
)
manipulate(
{
複数行にわたるスクリプト
},
picker, sliderの情報(複数の場合はカンマで結合)
)
\[Frequency=\frac{K}{Rank^A} \] K,A: 定数
K=freqMtx[1,1]
A=0.8
rank <- seq(1:dim(freqMtx)[1])
zipf <- K/rank^A
plot(zipf, log="xy", type="l",col="red" ,
xlim=c(1,nrow(freqMtx)),ylim=c(1,50),main="Zipf's Law", xlab="Rank", ylab="Frequency")
par(new=T)
plot(rank,freqMtx[,1], xlim=c(1,nrow(freqMtx)), ylim=c(1,50),log="xy",pch=8, col="darkgreen", main="Zipf's Law", xlab="Rank", ylab="Frequency")
配置:“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(shiny)
runApp("apps/app_hoge")