-
긍정 정서나 부정 정서에 가장 큰 기여를 한 단어들R/TextMining 2019. 10. 30. 00:05
# 패키지 설치하기와 로딩하기
install.packages("tm")
install.packages("topicmodels")
install.packages("tidyverse")
install.packages("tidytext")
library(tm)
library(topicmodels)
library(tidyverse)
library(tidytext)# 데이터 불러오기
data("AssociatedPress")
AssociatedPress# tidy data 만들기
ap_td <- tidytext::tidy(AssociatedPress)# 정서분석 데이터 만들기
ap_td %>%
dplyr::inner_join(tidytext::get_sentiments("bing"), by = c(term = "word")) -> ap_sentiments# 정서에 기여하는 단어들
ap_sentiments %>%
dplyr::count(sentiment, term, wt = count) %>%
dplyr::ungroup() %>%
dplyr::filter(n >= 200) %>%
dplyr::mutate(n = ifelse(sentiment == "negative", -n, n)) %>%
dplyr::mutate(term = reorder(term, n)) %>%
ggplot2::ggplot(mapping = aes(x = term, y = n, fill = sentiment)) +
ggplot2::geom_bar(stat = "identity") +
ggplot2::ylab("Contribution to sentiment") +
ggplot2::coord_flip()[출처] R로 배우는 텍스트마이닝, 줄리아 실기/데이비드 로빈슨 지음, 박진수 옮김, 제이펍, p85~88
'R > TextMining' 카테고리의 다른 글
term-topic probability (0) 2019.11.04 DFM 객체 정돈하기 (0) 2019.10.30 R and BERT (0) 2019.10.29 문재인 대통령 평양 연설문에 대한 Word Cloud 작성하기 (0) 2019.10.24 Jane Austen 소설 속 Term Frequency (0) 2019.10.21