在使用RStudio画图时,workspace browser内存中显示正常,但是画图时出现中文乱码,网上找了一下问题原因,得到:
sample.cloud <- function(cluster, maxwords = 100) {
words <- sample.words[which(csv$type==cluster)]
allwords <- unlist(words)
wordsfreq <- sort(table(allwords), decreasing = T)
wordsname <- names(wordsfreq)
png(paste("sample_", cluster, ".png", sep = ""), width = 600, height = 600 )
wordcloud(wordsname, wordsfreq, scale = c(6, 1.5), min.freq = 2, max.words = maxwords,
colors = rainbow(100),family='STXihei')
title(main = paste("cluster:", cluster))
dev.off()
}