Suppose we have a data frame (df
) containing comments (each row is a comment):
comment
Amazing job
Terrible work
And we have a dictionary (dict
) of positive and negative words:
positive negative
amazing terrible
I'm trying to create two word clouds: one of the positive comment in df
, and one of negative comment in df
. To do this, I tried the following code but run into an error. Can anyone suggest a fix?
library("quanteda")
corpus_example <- corpus(df)
head(corpus_example)
Output:
text1:
"Amazing job"
text2:
"Terrible work"
Next, create dfm:
comments_dfm <- dfm(corpus_example, dictionary = dict)
head(comments_dfm)
Output:
positive negative
text1 1 0
text2 0 1
I.e. it shows how many positive and negative words (according to dict
) exist within text1
and text2
. text1
is considered positive and text2
is considered negative.
Finally, I try to create word clouds using textplot_wordcloud(comments_dfm)
, but this just returns a word cloud containing the headers of comments_dfm
, i.e. the words positive
and negative
. Instead, I want two word clouds: one containing Amazing job
(because it's considered a positive comment), the other containing Terrible work
(because it's a negative comment).
Does anyone know how to fix this?