Target Social
2022-08-14
Overview/Comparison: Twitter
install.packages(“tidyverse”) install.packages(“lubridate”) install.packages(“dplyr”) install.packages(“ggplot2”) install.packages(“tidyr”) install.packages(“viridisLite”) install.packages(“scales”) install.packages(“devtools”) install.packages(“remotes”) remotes::install_github(“hadley/devtools”) remotes::install_github(“gadenbuie/cleanrmd”) install.packages(“magrittr”)
Loading Environment
library("magrittr")
library(lubridate)##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
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
library(ggplot2)
library(tidyr)##
## Attaching package: 'tidyr'
## The following object is masked from 'package:magrittr':
##
## extract
library(viridisLite)
library(scales)
library(devtools)## Loading required package: usethis
Importing Data
target_twitter <- read.csv(file = "Target Twitter Data T1 V2.csv",header = TRUE, sep = ",")
walmart_twitter <- read.csv(file = "Walmart Twitter V2.csv",header = TRUE, sep = ",")Data Transformation
retweets <- target_twitter$public_metrics.retweet_count
replies <- target_twitter$public_metrics.reply_count
likes <- target_twitter$public_metrics.like_count
quotes <- target_twitter$public_metrics.quote_count
time <- target_twitter$time2
retweets <- walmart_twitter$Column1.public_metrics.retweet_count
replies <- walmart_twitter$Column1.public_metrics.reply_count
likes <- walmart_twitter$Column1.public_metrics.like_count
quotes <- walmart_twitter$Column1.public_metrics.quote_countSummary of Datasets
summary(target_twitter) ## possibly_sensitive text date time
## Mode :logical Length:33 Length:33 Length:33
## FALSE:33 Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
## created_at public_metrics.retweet_count public_metrics.reply_count
## Length:33 Min. : 8.00 Min. : 10.00
## Class :character 1st Qu.: 18.00 1st Qu.: 20.00
## Mode :character Median : 35.00 Median : 52.00
## Mean : 99.88 Mean : 76.94
## 3rd Qu.: 69.00 3rd Qu.: 89.00
## Max. :566.00 Max. :446.00
## public_metrics.like_count public_metrics.quote_count id
## Min. : 29.0 Min. : 0.00 Min. :1.532e+18
## 1st Qu.: 138.0 1st Qu.: 2.00 1st Qu.:1.537e+18
## Median : 271.0 Median : 8.00 Median :1.545e+18
## Mean : 693.4 Mean : 19.18 Mean :1.544e+18
## 3rd Qu.: 582.0 3rd Qu.: 28.00 3rd Qu.:1.550e+18
## Max. :3734.0 Max. :141.00 Max. :1.558e+18
summary(walmart_twitter)## retweet_count Column1.public_metrics.retweet_count reply_count
## Min. : 1.62 Min. : 1.00 Min. : 4.86
## 1st Qu.: 12.55 1st Qu.: 7.75 1st Qu.: 17.82
## Median : 16.20 Median : 10.00 Median : 27.54
## Mean : 23.63 Mean : 14.59 Mean : 46.24
## 3rd Qu.: 29.16 3rd Qu.: 18.00 3rd Qu.: 45.36
## Max. :309.42 Max. :191.00 Max. :691.74
## Column1.public_metrics.reply_count like_count
## Min. : 3.00 Min. : 11.34
## 1st Qu.: 11.00 1st Qu.: 56.30
## Median : 17.00 Median : 81.81
## Mean : 28.54 Mean : 116.88
## 3rd Qu.: 28.00 3rd Qu.: 151.06
## Max. :427.00 Max. :1106.46
## Column1.public_metrics.like_count quote_count
## Min. : 7.00 Min. : 0.000
## 1st Qu.: 34.75 1st Qu.: 0.000
## Median : 50.50 Median : 1.620
## Mean : 72.15 Mean : 4.017
## 3rd Qu.: 93.25 3rd Qu.: 3.240
## Max. :683.00 Max. :132.840
## Column1.public_metrics.quote_count possibly_sensitive id
## Min. : 0.00 Mode :logical Min. :1.532e+18
## 1st Qu.: 0.00 FALSE:148 1st Qu.:1.538e+18
## Median : 1.00 Median :1.548e+18
## Mean : 2.48 Mean :1.547e+18
## 3rd Qu.: 2.00 3rd Qu.:1.553e+18
## Max. :82.00 Max. :1.558e+18
## date time created_at text
## Length:148 Length:148 Length:148 Length:148
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
Adding Week Day Column to Both Datasets
target_twitter <- target_twitter %>%
mutate(date=ymd(date))
target_twitter$weekday <- weekdays(target_twitter$date)
walmart_twitter <- walmart_twitter %>%
mutate(date=ymd(date))
walmart_twitter$weekday <- weekdays(walmart_twitter$date)Organizing by Day of the Week
target_twitter$weekday <- factor(target_twitter$weekday , levels = c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"))
walmart_twitter$weekday <- factor(walmart_twitter$weekday , levels = c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"))Data Vizulization
ggplot(target_twitter, aes(weekday, public_metrics.retweet_count))+
labs(title = "Target Daily Retweets", x = "", y = "")+
geom_boxplot()+
theme(plot.title = element_text(hjust = 0.5, size = 16))ggplot(walmart_twitter, aes(weekday, retweets))+
labs(title = "Walmart Daily Retweets", x = "", y = "")+
geom_boxplot()+
theme(plot.title = element_text(hjust = 0.5, size = 16))ggplot(target_twitter, aes(weekday, public_metrics.like_count))+
labs(title = "Target Daily Likes", x = "", y = "")+
geom_boxplot()+
theme(plot.title = element_text(hjust = 0.5, size = 16))ggplot(walmart_twitter, aes(weekday, likes))+
labs(title = "Walmart Daily Likes", x = "", y = "")+
geom_boxplot()+
theme(plot.title = element_text(hjust = 0.5, size = 16))ggplot(target_twitter, aes(weekday, public_metrics.reply_count))+
labs(title = "Target Daily Likes", x = "", y = "")+
geom_boxplot()+
theme(plot.title = element_text(hjust = 0.5, size = 16))ggplot(walmart_twitter, aes(weekday, replies))+
labs(title = "Walmart Daily Likes", x = "", y = "")+
geom_boxplot()+
theme(plot.title = element_text(hjust = 0.5, size = 16))ggplot(target_twitter, aes(weekday, public_metrics.quote_count))+
labs(title = "Target Daily Likes", x = "", y = "")+
geom_boxplot()+
theme(plot.title = element_text(hjust = 0.5, size = 16))ggplot(walmart_twitter, aes(weekday, quotes))+
labs(title = "Walmart Daily Likes", x = "", y = "")+
geom_boxplot()+
theme(plot.title = element_text(hjust = 0.5, size = 16))ggplot(target_twitter, aes(public_metrics.retweet_count, time))+
labs(title = "Target Daily Retweets", x = "", y = "")+
geom_boxplot()+
theme(plot.title = element_text(hjust = 0.5, size = 16))ggplot(walmart_twitter, aes(retweets, time))+
labs(title = "Walmart Daily Retweets", x = "", y = "")+
geom_boxplot()+
theme(plot.title = element_text(hjust = 0.5, size = 16))ggplot(target_twitter, aes(public_metrics.like_count, time))+
labs(title = "Target Daily Likes", x = "", y = "")+
geom_boxplot()+
theme(plot.title = element_text(hjust = 0.5, size = 16))ggplot(walmart_twitter, aes(likes, time))+
labs(title = "Walmart Daily Likes", x = "", y = "")+
geom_boxplot()+
theme(plot.title = element_text(hjust = 0.5, size = 16))ggplot(target_twitter, aes(public_metrics.reply_count, time))+
labs(title = "Target Daily Likes", x = "", y = "")+
geom_boxplot()+
theme(plot.title = element_text(hjust = 0.5, size = 16))ggplot(walmart_twitter, aes(replies, time))+
labs(title = "Walmart Daily Likes", x = "", y = "")+
geom_boxplot()+
theme(plot.title = element_text(hjust = 0.5, size = 16))ggplot(target_twitter, aes(public_metrics.quote_count, time))+
labs(title = "Target Daily Likes", x = "", y = "")+
geom_boxplot()+
theme(plot.title = element_text(hjust = 0.5, size = 16))ggplot(walmart_twitter, aes(quotes, time))+
labs(title = "Walmart Daily Likes", x = "", y = "")+
geom_boxplot()+
theme(plot.title = element_text(hjust = 0.5, size = 16))