问题描述
我的Twitter数据的“文字”和“国家/地区”列,并希望绘制一个字云,其中的颜色会因国家/地区而异。类似于此处的第二个单词云:https://quanteda.io/articles/pkgdown/examples/plotting.html
# create a table with tweets and Country
tweets_country <- uk_tweets %>%
select(Country,text)
# combine tweets by country
tweets_country <- tweets_country %>%
group_by(Country) %>%
summarise(text = paste(text,collapse = " "))
# remove unkNown locations
tweets_country <- tweets_country[-c(5),]
# create a corpus
corp_tweets <- corpus(tweets_country) %>%
print(corp_tweets)
# change document names to each country
docid <- paste(tweets_country$Country,sep = " ")
docnames(corp_tweets) <- docid
print(corp_tweets)
corp_sub <- corpus_subset(corp_tweets,Country %in% c('England','Scotland','northern Island','Wales'))
dfmat2 <- dfm(corpus_subset(corp_sub,Country %in% c("England","Scotland","northern Island","Wales")),remove = stopwords("english"),remove_punct = TRUE,groups = "Country") %>%
dfm_trim(min_termfreq = 3)
extplot_wordcloud(dfmat2,comparison = TRUE,max_words = 300,color = c("blue","red","green","purple"))
我尝试了多个代码,每次我得到一个不同的错误(包括创建语料库时的错误)时,也会出现此错误: 不建议使用“ structure(NULL,*)”,因为NULL不能具有属性。 请考虑使用“ structure(list(),*)”。x [[length(x)]]中的错误: 尝试在integerOneIndex中选择少于一个元素
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)