首页 文章

无法使用ggplot2 [暂停]可视化字数统计图

提问于
浏览
0

我有一个整洁的文档术语矩阵,我已成功完成情绪分析,现在我试图通过使用ggplot2绘制单词来查看哪些词通常对正面或负面情绪有贡献 .

到目前为止我有这个:

dtm_sentiments %>%
  count(sentiment, term, wt = count) %>%
  ungroup() %>%
  filter(n >= 200) %>%
  mutate(n = ifelse(sentiment == "negative", -n, n)) %>%
  mutate(term = reorder(term, n)) %>%
  ggplot(aes(term, n, fill = sentiment)) +
  geom_bar(stat = "identity") +
  ylab("Contribution to sentiment") +
  coord_flip()

但不断收到错误代码:计数错误( . ,情绪,术语,wt =计数):未使用的参数(术语) .

有没有人对这个错误发生的原因有任何想法?

谢谢!

1 回答

  • 1

    使用tidytext包中的情绪数据并调整代码,我们有:

    sentiments %>% 
      count(word,sentiment) %>%
      ungroup() %>%
      filter(n >= 2) %>%
     mutate(n = ifelse(sentiment == "negative", -n, n)) %>%
      mutate(word= reorder(word, n)) %>%
      sample_n(45) %>% 
      ggplot(aes(word, n, fill = sentiment)) +
      geom_bar(stat = "identity") +
      ylab("Contribution to sentiment") +
      coord_flip()
    

    这给出了以下情节:虽然我认为wordcloud会更好 .

相关问题