Wordcloud and plotting sentiment score error


#1

creating a wordcloud, but its not plotting and am getting this error ;

## Wordcloud code
pal <- brewer.pal(8, "Dark2")

png("wordcloud_packages.png", width=1500,height=1500)

wordcloud(some_txt6, min.freq = 5, max.words=Inf, random.order=FALSE, rot.per=0.35, 
          colors=pal)
dev.off()

error:

png 
  2

am also trying to plot my sentiments graph with this code...

## Sentiment Analysis
# Build a term-document matrix -2- ON A TABLE 
mysentiment <- get_nrc_sentiment(some_txt5)

SentimentScores <- data.frame(colSums(mysentiment[,]))

names(SentimentScores) <- "Score"

SentimentScores <- cbind("Sentiment" = rownames(SentimentScores), SentimentScores)

rownames(SentimentScores) <- NULL

# plot Sentiment Score data on a graph
ggplot(data = SentimentScores, aes(x = sentiment, y=Score)) + geom_bar(aes(fill = sentiment), stat = "identity") +
  theme(legend.position = "none") +
  xlab("sentiment") + ylab("Score") + 
  ggtitle("Total Sentiment Score Based on Tweets")

error:

Error in FUN(X[[i]], ...) : object 'sentiment' not found

please someone help me out?....

System Information:

  • RStudio Edition: (Desktop or Server)
  • RStudio Version:
  • OS Version:
  • R Version:
  • sessionInfo():

Referred here from support.rstudio.com


#2

Hi! Welcome!

For the second problem, I think it’s just a typo. The code names the variables in SentimentScores as Sentiment and Scores, but in the ggplot call, the x variable is given as sentiment (all lowercase). R is case sensitive, so x needs to be specified as Sentiment, instead.

For the first problem, this will be a lot easier to solve if helpers can run the code and experiment with it. Can you turn this into a self-contained, reproducible example? You’re pretty close — the additional components you’d need to supply are:

  • sample data
  • the relevant library() calls

See the link above for lots more help on turning your problem into a reproducible example. It’s the single best thing you can do to make getting an answer more likely! :grin: