Introduction

*Twitter started its service in 2006. It has been almost 14 years for it to appear in human’s daily life.

*Kwak, Lee, Park, and Moon (2010) has proposed a topological study about Twitter’s information sharing power by including data about user profiles,social relations,trending topics, etc. It is displayed as the first quantitative analysis on “Twittersphere.”

*Milgram (1967) :‘six degrees of separation’ theory

*The relationship between social network and language has been widely discussed in many studies as in Dieckhoff(2004), Jaspal (2010), Rampton(2017), and Harris (2006).

load("C:/Users/User/Desktop/修課/108-1/108-1R/W3twitter api_ass1/twitter_token.RData")
library(rvest)
## Loading required package: xml2
library(stringr)
library(data.table)
library(rtweet)
library(plyr)
library(stringr)
library(ggplot2)
table_df <- function(data_vector) {
  # create the table, create the df and then order
  df <- as.data.frame(table(data_vector), stringsAsFactors=F)
  df <- df[order(df$Freq, decreasing = T), ]
  # return as value the df
  # just call the df or use return
  return(df)
}
library(RColorBrewer)
library(wordcloud)
library(maps)
## Warning: package 'maps' was built under R version 3.6.3
## 
## Attaching package: 'maps'
## The following object is masked from 'package:plyr':
## 
##     ozone

A. Music Genre Corpus: Listeners’ angle

load("~/genrelocdf.RData")
library(ggplot2)
#theme_set(theme_bw())
library("sf")
## Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library("rnaturalearth")
library("rnaturalearthdata")
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
## The following objects are masked from 'package:data.table':
## 
##     between, first, last
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
require(maps)
require(viridis)
## Loading required package: viridis
## Loading required package: viridisLite
#theme_set(theme_void())
#world <- ne_countries(scale = "medium", returnclass = "sf")
#class(world)
#map<-ggplot(data = world) +
#  geom_sf() +
#  xlab("Longitude") + ylab("Latitude") +
#  ggtitle("World map", subtitle = paste0("(", length(unique(world$name_sort)), " countries)"))
#class(genrelocdf$lat)#character 所以在畫圖時要把他as.numeric
#map+geom_point(data =genrelocdf, aes(x = as.numeric(lon), y = as.numeric(lat),color=genre))

` # B. Best Music Tweets List Corpus: Musicians’ angle ## in degree out degree

roles <- c("questlove", "amazonmusic")
load("C:/Users/User/Desktop/修課/108-1/108-1R/w9 text minig/code/bm_tfidf_order.RData")
library(tidytext)
library(stringr)
inout_idf<-bm_tfidf_order %>% filter(screen_name %in% roles,!str_detect(word, "^@"),!str_detect(word,"^http"))
#View(inout_idf)
#inout_idf %>%
#  arrange(desc(tf_idf)) %>%
#  mutate(word = factor(word, levels = rev(unique(word)))) %>% 
#  group_by(screen_name) %>% 
#  top_n(15) %>% 
#  ungroup() %>%
#  ggplot(aes(word, tf_idf, fill = screen_name)) +
#  geom_col(show.legend = FALSE) +
#  labs(x = NULL, y = "tf-idf") +
#  facet_wrap(~screen_name, ncol = 2, scales = "free") +
#  coord_flip()

central actors

roles <- c("freddurst","AudioPush")
cent_idf<-bm_tfidf_order %>% filter(screen_name %in% roles,!str_detect(word, "^@"),!str_detect(word,"^http"))
#cent_idf %>%
#  arrange(desc(tf_idf)) %>%
#  mutate(word = factor(word, levels = rev(unique(word)))) %>% 
#  group_by(screen_name) %>% 
#  top_n(15) %>% 
#  ungroup() %>%
#  ggplot(aes(word, tf_idf, fill = screen_name)) +
#  geom_col(show.legend = FALSE) +
#  labs(x = NULL, y = "tf-idf") +
#  facet_wrap(~screen_name, ncol = 2, scales = "free") +
#  coord_flip()

btw:“pitchfork”,“diplo”,“QuincyDJones”

roles <- c("pitchfork","diplo","QuincyDJones")
btw_idf<-bm_tfidf_order %>% filter(screen_name %in% roles,!str_detect(word, "^@"),!str_detect(word,"^http"))