Lab 12
Mentions of the topic | ||
Topic | Count | Percent |
---|---|---|
0 | 4741 | 86.5 |
1 | 738 | 13.5 |
Mentions of the topic | ||
Topic | Count | Percent |
---|---|---|
0 | 5035 | 91.9 |
1 | 444 | 8.1 |
Code:
# Load packages
if (!require("tidyverse")) install.packages("tidyverse")
if (!require("tidytext")) install.packages("tidytext")
if (!require("plotly")) install.packages("plotly")
if (!require("gtExtras")) install.packages("gtExtras")
library(tidyverse)
library(tidytext)
library(gtExtras)
library(plotly)
library(lubridate)
# Read the data
mydata <- read.csv("https://raw.githubusercontent.com/drkblake/Data/main/NikeUniforms.csv")
# Counting posts about Biden
tidy_text <- mydata %>%
unnest_tokens(word,Full.Text) %>%
count(word, sort = TRUE)
# Deleting standard stop words
data("stop_words")
tidy_text <- tidy_text %>%
anti_join(stop_words)
# Deleting custom stop words
my_stopwords <- tibble(word = c("https",
"t.co",
"rt"))
tidy_text <- tidy_text %>%
anti_join(my_stopwords)
head(tidy_text, 25)
searchterms <- "sexist|vagina|suit"
mydata$Topic <- ifelse(grepl(searchterms,
mydata$Full.Text,
ignore.case = TRUE),1,0)
Topic <- mydata %>%
group_by(Topic) %>%
summarize(
Count = n(),
Percent = round(n() / nrow(mydata) * 100, 1)
)
TopicTable <- gt(Topic) %>%
tab_header("Mentions of the topic") %>%
cols_align(align = "left") %>%
gt_theme_538
TopicTable
# Load packages
if (!require("tidyverse")) install.packages("tidyverse")
if (!require("tidytext")) install.packages("tidytext")
if (!require("plotly")) install.packages("plotly")
if (!require("gtExtras")) install.packages("gtExtras")
library(tidyverse)
library(tidytext)
library(gtExtras)
library(plotly)
library(lubridate)
# Read the data
mydata <- read.csv("https://raw.githubusercontent.com/drkblake/Data/main/NikeUniforms.csv")
# Counting posts about Nike
tidy_text <- mydata %>%
unnest_tokens(word,Full.Text) %>%
count(word, sort = TRUE)
# Deleting standard stop words
data("stop_words")
tidy_text <- tidy_text %>%
anti_join(stop_words)
# Deleting custom stop words
my_stopwords <- tibble(word = c("https",
"t.co",
"rt"))
tidy_text <- tidy_text %>%
anti_join(my_stopwords)
head(tidy_text, 25)
searchterms <- "female|bathing|uniform"
mydata$Topic <- ifelse(grepl(searchterms,
mydata$Full.Text,
ignore.case = TRUE),1,0)
Topic <- mydata %>%
group_by(Topic) %>%
summarize(
Count = n(),
Percent = round(n() / nrow(mydata) * 100, 1)
)
TopicTable2 <- gt(Topic) %>%
tab_header("Mentions of the topic") %>%
cols_align(align = "left") %>%
gt_theme_538
TopicTable2