library(rtweet)
library(igraph)
library(ggraph)
library(jsonlite)
library(tidygraph)
library(dplyr)
library(tidyr)
library(miceadds)
setwd("~/Documents/ESCP/Consumer Insight Analytics/Berlin Semester")
set.seed(123)
rt <- search_tweets(
"#tesla lang:en", n = 1000, include_rts = TRUE, parse = TRUE, type = "mixed"
)
rt_net <- network_graph(rt, .e="retweet")
print(rt_net)
## IGRAPH 9f012cd DN-- 767 563 --
## + attr: id (v/c), name (v/c), type (e/c)
## + edges from 9f012cd (vertex names):
## [1] MADSTANG68 ->TeslaNY Marilou858 ->EtagereAntiques
## [3] OscarJerome_ ->stevenmarkryan XZPwEDVhHH37i3C->schmarzo
## [5] TeslaOwnersPA ->DriveTeslaca relativelyr ->vincent13031925
## [7] c_labrinos ->macrosandchaos c_labrinos ->JohnSoua
## [9] c_labrinos ->Tickeron c_labrinos ->ElectricTempus
## [11] c_labrinos ->gora321 c_labrinos ->ElliottForecast
## [13] c_labrinos ->TNR_Gold c_labrinos ->MemesOfMars
## [15] c_labrinos ->28delayslater iinnovadoras ->schmarzo
## + ... omitted several edges
ggraph(rt_net, layout = "graphopt") +
geom_node_point(aes(size = centrality_degree())) +
geom_edge_link(alpha = 0.8) +
theme_graph()
deg.in <- degree(rt_net, mode = "in")
deg.in <- sort(deg.in, decreasing = T)[1:10]
deg.out <- degree(rt_net, mode = "out")
deg.out <- sort(deg.out, decreasing = T)[1:10]
deg.all <- degree(rt_net, mode = "all")
deg.all <- sort(deg.all, decreasing = T)[1:10]
deg <- data.frame(cbind(deg.in, deg.out, deg.all))
colnames(deg) <- c("deg.in", "deg.out", "deg.all")
deg <- tidyr::gather(deg)
deg$name[1:10] <- names(deg.in)
deg$name[11:20] <- names(deg.out)
deg$name[21:30] <- names(deg.all)
ggplot(deg) +
geom_col(aes(x = reorder(name,value), y = value)) +
coord_flip() +
facet_wrap(~ key, scales = "free") +
labs(x="screen_name")+
ggpubr::theme_pubr()
According to the out-degree centrality, kirillklip is the top influencer since he/she is retweeted the most, therefore, I would target him/her. We could use this information with textual analysis and do some some topic and/or sentiment analysis to see what topics are discussed by kirillklip and what is his/her sentiment towards Tesla. It makes sense to analyze the opinions of the most retweeted accounts since they often express the feelings of the majority and they also can be used to influence the majority.
## [1] "Number of edges:"
## [1] 563
## [1] "Number of vertices:"
## [1] 767
## [1] "Edge Density:"
## [1] 0.000958262
We can see from the network graph that #Tesla has a better network than #Facebook since more nodes are connected with each other. Furthermore, the edge density is of 0.002 for Tesla, which is above Facebook’s (i.e. 0.0007).