This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
text <- c("I love the quality of this product. The price is reasonable, and delivery was fast.",
"The product quality is excellent, but the shipping took too long.",
"Great customer service! I would definitely recommend this product to my friends.",
"The price is too expensive. However, the product looks beautiful.",
"Fast delivery and excellent service. I am very satisfied with my purchase.")
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
text_df <- tibble(line = 1:5, text = text)
library(tidytext)
text_df <-text_df %>%
unnest_tokens(word, text)
data(stop_words)
text_df <- text_df %>%
anti_join(stop_words)
## Joining with `by = join_by(word)`
text_df %>%
count(word, sort = TRUE)
## # A tibble: 17 × 2
## word n
## <chr> <int>
## 1 product 4
## 2 delivery 2
## 3 excellent 2
## 4 fast 2
## 5 price 2
## 6 quality 2
## 7 service 2
## 8 beautiful 1
## 9 customer 1
## 10 expensive 1
## 11 friends 1
## 12 love 1
## 13 purchase 1
## 14 reasonable 1
## 15 recommend 1
## 16 satisfied 1
## 17 shipping 1
library(ggplot2)
text_df %>%
count(word, sort = TRUE) %>%
filter(n > 1) %>%
mutate(word = reorder(word, n)) %>%
ggplot(aes(n, word)) +
geom_col() +
labs(y = NULL)