Lecture 13: 視覚化ツール wordcouldパッケージ

準備

getFreqMtxDir関数の読み込み

source("getFreqMtxDir.R")

getFreqMtxDir()の実行

テキストファイルが格納されているフォルダを指定

univ <- getFreqMtxDir("msgs", encoding = "sjis")

最初の文字が数字で始まるものを排除

digits <- univ[grep(rownames(univ), pattern = "^[[:alpha:]]"), ]
univ <- univ[rownames(univ) %in% rownames(digits), ]

wordcouldパッケージ

wordcouldパッケージのインストール

install.packages("wordcloud")

wordcouldパッケージのロード

library("wordcloud")
## Warning: package 'wordcloud' was built under R version 3.0.2
## Loading required package: Rcpp
## Warning: package 'Rcpp' was built under R version 3.0.2
## Loading required package: RColorBrewer

wordcould実行例(ICU.txt)

wordcloud(rownames(univ), univ[, 1])

plot of chunk unnamed-chunk-6

wordcould実行例(kyotoU.txt):文字の色

wordcloud(rownames(univ), univ[, 2], color = rainbow(25))

plot of chunk unnamed-chunk-7

wordcould実行例(rits.txt):文字の大きさ

表示されない単語が出てくる可能性もあるので注意!

wordcloud(rownames(univ), univ[, 3], color = rainbow(25), scale = c(8, 1))

plot of chunk unnamed-chunk-8

pngファイルに保存

png("wordcloud.png", width = 600, height = 600)
wordcloud(rownames(univ), univ[, 2], color = rainbow(25), scale = c(8, 1))
dev.off()

各行の頻度合計が5以上の単語に限定

dim(univ)
## [1] 870   5
univ2 <- univ[rowSums(univ) >= 5, ]
dim(univ2)
## [1] 84  5

comparison.could実行例:5大学比較

comparison.cloud(univ2)

plot of chunk unnamed-chunk-11

comparison.cloud(univ2[, 3:4])
## Warning: minimal value for n is 3, returning requested palette with 3 different levels

plot of chunk unnamed-chunk-11

comparison.cloud(univ2[, c(T, F, F, T, F)])
## Warning: minimal value for n is 3, returning requested palette with 3 different levels

plot of chunk unnamed-chunk-11

comparison.could実行例

comparison.cloud(univ2)

plot of chunk unnamed-chunk-12

comparison.could実行例:部分比較1

3-4列目だけで比較

comparison.cloud(univ2[, 3:4])
## Warning: minimal value for n is 3, returning requested palette with 3 different levels

plot of chunk unnamed-chunk-13

comparison.could実行例::部分比較2

c(T,F,F,T,F) 比較する列はT,比較しない列はF

comparison.cloud(univ2[, c(T, F, F, T, F)])
## Warning: minimal value for n is 3, returning requested palette with 3 different levels

plot of chunk unnamed-chunk-14

commonality.could実行例:5大学比較

commonality.cloud(univ2)

plot of chunk unnamed-chunk-15

commonality.could実行例:部分比較1

3-4列目だけで比較

commonality.cloud(univ2[, 3:4])

plot of chunk unnamed-chunk-16

commonality.could実行例:部分比較2

c(T,F,F,T,F) 比較する列はT,比較しない列はF

commonality.cloud(univ2[, c(T, F, F, T, F)])

plot of chunk unnamed-chunk-17

Keyness単語の表示

rits.txtのKeynessを取得し、ファイルに保存(前回の実習)

Keynessファイル(値付き)の読み込み

keyness <- read.csv("rits-keynessValues.csv", header = T, row.names = 1)

wordcould実行

wordcloud(rownames(keyness), keyness[, 1], color = rainbow(10))

plot of chunk unnamed-chunk-19