コピペしているものをワードクラウドにする(指定した日本語フォントで)
関数はちょっと手直しをした。
日本語フォントはあらかじめwindowsFontsで設定した上で引数に「family=なんとか」と与えて描画する。
#関数を定義しておく clpcloud <- function(type=NULL, min=1, ...){ require(RMeCab) require(wordcloud) require(plyr) require(RColorBrewer) if( .Platform$OS.type=="unix"){ txt <- read.delim(pipe("pbpaste"), as.is=TRUE, header=FALSE) }else{ txt <- read.delim("clipboard", as.is=TRUE, header=FALSE) } res <- unlist(apply(txt,1,RMeCabC, mypref=1)) #助詞等を除く res <- res[!(attr(res, "names") %in% c("助詞", "記号", "助動詞", "接頭詞","連体詞"))] if(is.null(type)){ res <- res } else { res <- res[attr(res, "names") %in% type] } item <- data.frame(hinsi=attr(res, "names"), word=res, stringsAsFactors=FALSE) res <- ddply(item, .(hinsi, word), summarise, count=sum(!is.na(word))) res$count <- res$count pal <- brewer.pal(9,"BuGn")[5:9] wordcloud(res$word, res$count, min.freq=min, colors=pal, ...) } #フォントを設定しておく windowsFonts(JP1 = windowsFont("MS Mincho"), JP2 = windowsFont("MS Gothic"), JP3 = windowsFont("Arial Unicode MS"), JP4 = windowsFont("Meiryo UI"), JP5 = windowsFont("HGMaruGothicMPRO")) #描画 clpcloud(family="JP1") clpcloud(family="JP2") clpcloud(family="JP3") clpcloud(family="JP4") clpcloud(family="JP5")