Word Cloud code for R/R Studio

## Text modeling
# Word Cloud

### Set working directory
setwd(“C:/Users/spaceloss/Desktop”)

## text file

text
# Word Cloud

library(tm)
library(SnowballC)
library(wordcloud)
library(RColorBrewer)
source <- DirSource(“/Users/spaceloss/Desktop/text”)
source <- DirSource(“/Users/spaceloss/Desktop/text”)
corpus <- Corpus(source, readerControl=list(reader=readPlain, language=”eng”))

summary(corpus)

corpus <- tm_map(corpus, PlainTextDocument)
corpus <- tm_map(corpus, content_transformer(tolower))
corpus <- tm_map(corpus, removeNumbers)
corpus <- tm_map(corpus, removePunctuation)
corpus <- tm_map(corpus, removeWords, c(stopwords(“english”), “musk”))

wordcloud(corpus, max.words = 1000
,random.order = FALSE)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s