AnswerBun.com

R wordcloud error, invalid cex, unsure of reason

Stack Overflow Asked by Mia P on July 27, 2020

I can’t quite figure out whats wrong, perhaps cause I don’t completely understand text mining in the first place. The syntax tends to confuse me… but I digress, this is following a tutorial yet I’ve come up with an error. the one in particular well,,

Error in strwidth(words[i], cex = size[i], ...) : invalid 'cex' value

As the title implies I’m trying to use the wordcloud. However I turn up with this error when I use it. If you’re curious about what data I have, I’m using the same database referenced in this post which the kind lads there helped me within SQL. But now I’m using R…. here is the code in question.

# Word cloud
#  Installin packages and libs
install.packages("SnowballC")
library("tm")
library("wordcloud")
library ("SnowballC")

#  using negative tweets and loading them into corpus
negative <- idadf(mycon, "SELECT   TEXT 
                            FROM  GOP_DEBATE 
                            WHERE GOP_DEBATE.SENTIMENT='negative'")

docs<-VectorSource(negative$TEXT)
docs<-Corpus(docs)

#  Prepocessing (cleaning)
docs <- tm_map(docs, stripWhitespace)

#   remoce white space and urls
removeInvalid<-function(x) gsub("[^x01-x7F]", "", x)
docs <- tm_map(docs, content_transformer(removeInvalid))

removeURL <- function(x) gsub("http[^[:space:]]*", "", x)
docs <- tm_map(docs, content_transformer(removeURL))

#   Remove punctuation
docs <- tm_map(docs, removePunctuation)
toSpace <- content_transformer(function (x , pattern ) gsub(pattern, " ", x))
docs <- tm_map(docs, toSpace, "@")   #Remove @
docs <- tm_map(docs, toSpace, "/")   #Remove /
docs <- tm_map(docs, toSpace, "\|") #Remove |

#   remove the numbers
docs <- tm_map(docs, removeNumbers)

#   lowercasing text
docs <- tm_map(docs, tolower)

#   Stop words
docs <- tm_map(docs, removeWords, stopwords("english"))
docs <- tm_map(docs, removeWords, stopwords("SMART"))

#   additional white spaces
docs <- tm_map(docs, stripWhitespace)

#    stemming
docs <- tm_map(docs, stemDocument)

#    document matrix
dtm <- DocumentTermMatrix(docs)

# Convert dtm to a matrix
m <- as.matrix(dtm)  

# create cloud
dtms <- removeSparseTerms(dtm, 0.6)    
freq <- colSums(as.matrix(dtm)) 
dark2 <- brewer.pal(6, "Dark2")   
wordcloud(names(freq), freq, min.freq=35, max.words=100, rot.per=0.2, scale=c(0.9, 0.9), colors=dark2)

any help is appreciated!

Add your own answers!

Related Questions

Main Thread Checker Error: Double to UILabel Fails Swift

1  Asked on December 13, 2021 by nisse82

     

Can’t create bitmap without Color space android

1  Asked on December 13, 2021 by iheb-404-notfound

       

fetch id who have register all adv

1  Asked on December 11, 2021 by user13974528

   

Is there a better way to write this snippet in python?

3  Asked on December 11, 2021 by paulo-sergio-schlogl

 

How to set if-else statement in a React function Return()?

4  Asked on December 11, 2021 by buffaurus

   

Check if the next item is 1 unit longer (Javascript)

3  Asked on December 11, 2021 by ekhi-arzac

   

adding onclick to an array of items

5  Asked on December 11, 2021 by helpmepiliizz

       

How to make sure only 1 thread is running? C++

1  Asked on December 11, 2021 by lordi1000

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir