arg <- 4
sqrt <- sqrt(arg)
paste("平方根は",arg)
## [1] "平方根は 4"
printSQRT(3)
## [1] "平方根は 3"
source("getRelativeFreqMtx.R")
freqMtx<-getRelativeFreqMtx("osaka-u.txt")
head(freqMtx)
## term raw relative
## 211 the 33 0.06470588
## 21 and 31 0.06078431
## 146 of 31 0.06078431
## 228 university 16 0.03137255
## 112 in 15 0.02941176
## 149 osaka 15 0.02941176
dim(freqMtx)
## [1] 246 3
tmp <-freqMtx[1:10,]$raw
tmp
## [1] 33 31 31 16 15 15 11 11 11 8
sort(tmp)
## [1] 8 11 11 11 15 15 16 31 31 33
order(tmp)
## [1] 10 7 8 9 5 6 4 2 3 1
subMtx <-as.table(freqMtx[1:20,2])
names(subMtx) <-freqMtx[1:20,]$term
title="Word Frequency Distribution"
xlabel="Word"
ylabel="Frequency"
barplot(subMtx, main=title, xlab=xlabel, ylab=ylabel,las=3)
colors = c("red", "yellow", "green", "violet", "orange", "blue", "pink", "cyan")
barplot(subMtx,col=colors, main=title, xlab=xlabel, ylab=ylabel,las=3)
plot(0,0,pch=8)
plot(0,0,pch=8,cex=5)
plot(0,0,pch=8,cex=5,col="red")
インタラクティブなプロット
install.packages("manipulate")
library(manipulate)
picker()関数
manipulate(plot(0,0,pch=8,cex=5,col=myColors), myColors=picker("red", "yellow", "green", "violet", "orange", "blue", "pink", "cyan") )
picker()関数
manipulate(
plot(0,0,pch=myMarkers,cex=5,col=myColors), myColors=picker("red", "yellow", "green", "violet", "orange", "blue", "pink", "cyan",initial="violet"),
myMarkers=picker(1,2,3,4,5,6,7,8,initial="5")
)
picker()関数
manipulate(
plot(0,0,pch=8,cex=mySize,col="blue"),
mySize=slider(1,10,initial=5)
)
plot(0,0,type="n")
text(0,0, "R",cex=1,col="blue")
manipulate({
plot(0,0,type="n")
text(0,0, "R",cex=1,col=myColors)
},
myColors=picker("red", "yellow", "green", "violet", "orange", "blue", "pink", "cyan") )
alt text
barplot(subMtx,col="red",main=title, xlab=xlabel, ylab=ylabel,las=3)
alt text
barplot(subMtx,col="green",main=title, xlab=xlabel, ylab=ylabel, xlim=c(1,20),las=3)
alt text