Original link:tecdat.cn/?p=5124

Original source:Tuo End number according to the tribe public number

 

Examples of tweets that contain the keyword “bioinformatics.

Step 1: Load the required software package

# load the required package library(igraph)Copy the code

 

Step 2: Collect tweets about “bioinformatics.

Dm_tweets = searchTwitter("bioinformatics", n=500) # get text dm_txt = sapply(dm_tweets, function(x) x$getText())Copy the code

Step 3: Identify the forward

Forward # to find regular expression of grep (" (RT | via) ((? : \ \ \ \ W * @ \ \ W + b) +) ", dm_tweets, # forward which tweet tweet rt_patterns = grep (" (RT | via) ((? :\\b\ W*@\ W +)+)", dm_txt, ignore.case=TRUE)Copy the code

Step 4: Collect who retweets and who posts

We will use these results to form a list of edges to create the graph

# Create list to store user name who_retweet = as.list(1:length(rt_patterns)) # for loop for (I in 1:length(rt_patterns)) {# get messages by forwarding entities twit = Dm_tweets [[rt_patterns [I]]] # turn get pushed source poster = str_extract_all (twit $getText (), "(RT | via) ((? : \ \ \ \ W * @ \ \ W + b) +) ") # delete ':' poster = gsub (" : ", "" unlist (poster) # forward username who_post [[I]] = gsub (" (RT @ | via @)", "", Poster, ignore.case=TRUE) # retweet[[I]] = rep(twit$getScreenName(), Length (poster)) # convert list to vector format who_post = unlist(who_post)Copy the code

Step 5: Create graphics from the edit list

# retweeter_poster = cbind(who_retweet, Rt_graph = graph.edgelist(retweeter_poster) # get.vertex. Attribute (rt_graph, "name", index=V(rt_graph))Copy the code

Step 6: Let’s draw the graph

# choose glay = layout drawing layout. Fruchterman. Reingold (rt_graph) # drawing par (bg = "gray15", mar = c (1,1,1,1)) plot (rt_graph, layout = glay, Vertex. Label. Color = HSV (h=0, s=0, v=.95, alpha=0.5), edge.width=3, edge.color= HSV (h=.95, s=1, v=.7, vertex. Alpha =0.5) # add title("\nTweets with 'bioinformatics': Who retweets whom", cx. Main =1, col.main="gray95") # add title("\nTweets with 'bioinformatics': Who retweets whom", cx.Copy the code

Step 7: Bioinformatics representation

Par (bg="gray15", mar=c(1,1,1,1)) plot(rt_graph, layout=glay, edge.color= HSV (h=.35, s=1, v=.7) Alpha =0.4) # Added title("Tweets with 'bioinformatics': Who retweets whom", cex.main=1, col.main="gray95", family="mono")Copy the code

 



Most welcome insight

1. All acupoints were analyzed by WEB complex network of SPS-Modeler

2. Community detection in social networks using R language and Python

3.R language text mining NASA data Network analysis, TF-IDF and topic modeling

4. Epidemic modeling using airline complex networks in R language

5. Python membership graph model Detection of dense overlapping communities in model-based networks

6. Analyze social networks using Python and SAS Viya

7. Association network analysis: Data portraits of migrants who have moved out of Beijing

8. Emotional Semantic network: Travel data perception of tourist destination image

9. Use association rule data mining to explore the rules of drug compatibility