I have created a wordcloud which contains Twitter mentions for February no problem. However, I want to be able to edit it, firstly trying to create a wordcloud using the Twitter logo and when that was unsuccessful I tried making one using the letter T. However this was also unsuccessful and i'm not sure why or how to resolve the issue. I'll input the code below so you can see where I'm going wrong.
.libPaths("M:/R")
library("tm")
library("SnowballC")
library("wordcloud")
library("RColorBrewer")
library("wordcloud2")
library("magrittr")
library("tidytext")
get_sentiments("afinn")
get_sentiments("bing")
get_sentiments("nrc")
#Loading the data as a corpus
corpus <- Corpus(DirSource(directory = "//ecfle35/STAFF-HOME$/MaxEmery/Twitter mentions"))
inspect(corpus)
#Remove special characters
toSpace <- content_transformer(function(x, pattern) gsub(pattern, "", x))
docs <- tm_map(corpus, toSpace, "/")
docs <- tm_map(corpus, toSpace, "@")
docs <- tm_map(corpus, toSpace, "\\|")
#Convert the text to lower case
docs <- tm_map(docs, content_transformer(tolower))
#Remove numbers
docs <- tm_map(docs, removeNumbers)
#Remove english common stopwords
docs <- tm_map(docs, removeWords, stopwords("english"))
#specify your stopwrods as a character vector
docs <- tm_map(docs, removeWords, c("exetercollege", "exeter", "execollsport", "pitchatpalace", "execolljapan", "day", "today", "sponsorship","thank", "http", "see", "https", "will", "exeapprentices", "business", "well", "first", "microsofteduk", "apprenticeships", "new", "looking", "team", "skills", "entrepreneurs", "microsoft"))
#Remove punctuations
docs <- tm_map(docs, removePunctuation)
#Get rid of extra white spaces
docs <- tm_map(docs, stripWhitespace)
#Text stemming (strip off common suffixes)
docs <- tm_map(docs, stemDocument)
#Build a term-document matrix (a table containing the frequency of the words)
dtm <- TermDocumentMatrix(docs)
m <- as.matrix(dtm)
v <- sort(rowSums(m), decreasing = TRUE)
d <- data.frame(word= names(v), freq=v)
head(d, 10)
#Generate the word cloud
set.seed(1234)
wordcloud(words = d$word, freq = d$freq, min.freq = 1,
max.words = 200, random.order = FALSE, rot.per = 0.35,
colors = brewer.pal(8, "Dark2"))
#Change the shape of the wordcloud
letterCloud(corpus, word = "T", color='random-light' , backgroundColor="black")
#Change the shape using your image
wordcloud2(demoFreq, figpath= "twitter.png", size= 1.5, color= "skyblue", backgroundColor="black")
Below is what the error says when i try inputting the code to change the shape of the wordcloud.
**> letterCloud(corpus, word = "T", color='random-light' , backgroundColor="black")**
**Error in as.data.frame.default(data) : **
** cannot coerce class ‘c("SimpleCorpus", "Corpus")’ to a data.frame**