Memvisualisasikan jaringan Twitter

Menganalisis Data Media Sosial dengan R

Sowmya Vivek

Data Science Coach

Ikhtisar pelajaran

  • Plot jaringan dengan parameter default
  • Terapkan atribut format untuk meningkatkan keterbacaan
  • Gunakan sentralitas dan atribut jaringan untuk memperkaya plot
Menganalisis Data Media Sosial dengan R

Lihat jaringan retweet

# View the retweet network
print.igraph(nw_rtweet)
IGRAPH e7e618c DN-- 21 39 -- 
+ attr: name (v/c), followers (v/c)
+ edges from e7e618c (vertex names):
 [1] w3daily    ->RealFirstBuzz   w3daily    ->RealFirstBuzz  
 [3] w3daily    ->Giasaysthat     w3daily    ->RealFirstBuzz  
 [5] VanesEtim  ->PotionVanity    VanesEtim  ->DAVIDxCGN      
 [7] VanesEtim  ->PotionVanity    VanesEtim  ->Avinash_galaxy 
 [9] VanesEtim  ->PotionVanity    VanesEtim  ->BklynLeague    
[11] RedNileShop->Macaw_Blink     RedNileShop->leuqimcouture  
[13] RedNileShop->StoreDiv        RedNileShop->PotionVanity   
[15] RedNileShop->SCISSORSAPPAREL RedNileShop->Themoon12961958
+ ... omitted several edges
Menganalisis Data Media Sosial dengan R

Buat plot jaringan dasar

# Create the base network plot
set.seed(1234)  
plot.igraph(nw_rtweet)
Menganalisis Data Media Sosial dengan R

Lihat plot jaringan dasar

Plot jaringan dasar

Menganalisis Data Media Sosial dengan R

Format plot

# Format the network plot with attributes
set.seed(1234)
plot(nw_rtweet, asp = 9/16, 
     vertex.size = 10,
     vertex.color = "lightblue",
     edge.arrow.size = 0.5,
     edge.color = "black",
     vertex.label.cex = 0.9,
     vertex.label.color = "black")
Menganalisis Data Media Sosial dengan R

Lihat plot yang sudah diformat

Plot jaringan yang sudah diformat

Menganalisis Data Media Sosial dengan R

Atur ukuran vertex berdasarkan out-degree

# Create a variable for out-degree
deg_out <- degree(nw_rtweet, mode = c("out"))
deg_out

Nilai out-degree

vert_size <- (deg_out * 2) + 10
Menganalisis Data Media Sosial dengan R

Tetapkan vert_size ke atribut ukuran vertex

# Assign vert_size to vertex size attribute and plot network
set.seed(1234)
plot(nw_rtweet, asp = 9/16, 
     vertex.size = vert_size,
     vertex.color = "lightblue", 
     edge.arrow.size = 0.5,
     edge.color = "black",
          vertex.label.cex = 1.2,
     vertex.label.color = "black")
Menganalisis Data Media Sosial dengan R

Lihat plot dengan atribut baru

Plot dengan atribut ukuran vertex

Menganalisis Data Media Sosial dengan R

Menambahkan atribut jaringan

  • Pengguna yang paling sering retweet dan punya banyak pengikut memberi nilai lebih
  • Plot jaringan pengguna yang sering retweet dan punya banyak pengikut
  • Tambahkan jumlah pengikut sebagai atribut jaringan
Menganalisis Data Media Sosial dengan R

Jumlah pengikut pengguna jaringan

# Import the followers count data frame
followers <- readRDS("follower_count.rds")
Menganalisis Data Media Sosial dengan R

Lihat data frame pengikut

# View the follower count
head(followers)
screen_name    followers_count
<fct>             <dbl>
adyo312            58        
AllesUndNix_       18        
Avinash_galaxy     1536        
BklynLeague        40        
DAVIDxCGN          267        
Giasaysthat        9139
Menganalisis Data Media Sosial dengan R

Jumlah pengikut pengguna jaringan

# Categorize high and low follower count
followers$follow <- ifelse(followers$followers_count > 500, "1", "0")
Menganalisis Data Media Sosial dengan R

Lihat data frame pengikut

# View the data frame with the new column
head(followers)
screen_name    followers_count    follow
<fct>              <dbl>          <chr>
adyo312              58              0    
AllesUndNix_         18              0    
Avinash_galaxy     1536              1    
BklynLeague          40              0    
DAVIDxCGN           267              0    
Giasaysthat        9139              1
Menganalisis Data Media Sosial dengan R

Tetapkan atribut jaringan

# Assign external network attributes to retweet network
V(nw_rtweet)$followers <- followers$follow
Menganalisis Data Media Sosial dengan R

Lihat atribut vertex

# View the vertex attributes
vertex_attr(nw_rtweet)

Atribut vertex

Menganalisis Data Media Sosial dengan R

Ubah warna vertex

# Set the vertex colors for the plot
sub_color <- c("lightgreen", "tomato")
set.seed(1234)
plot(nw_rtweet, asp = 9/16,
     vertex.size = vert_size,
     edge.arrow.size = 0.5,
     vertex.label.cex = 1.3,
     vertex.color = sub_color[as.factor(vertex_attr(nw_rtweet, "followers"))],
     vertex.label.color = "black",
     vertex.frame.color = "grey")
Menganalisis Data Media Sosial dengan R

Lihat plot yang diformat dengan atribut vertex

Plot berbasis atribut vertex

Menganalisis Data Media Sosial dengan R

Ayo berlatih!

Menganalisis Data Media Sosial dengan R

Preparing Video For Download...