I’m giving in. I’m finally learning how to do social network analysis R. What made me switch (from only UCINet and NodeXL)? Well, all my data lives in a MySQL database, and I have networks with millions of edges. R makes it really easy to connect to MySQL and create a data frame from data found there. That saves me about 20 minutes every time I want to do some analysis. No more selecting and downloading data and crashing UCINet and Excel, just
con <- dbConnect(MySQL(), user="user", password="pass", dbname="TwitterCollector", host="localhost")
mentions <- dbGetQuery(con, "SELECT * FROM tweet_mentions WHERE source_user_id IN (SELECT user_id FROM congress_attributes) AND target_user_id IN (SELECT user_id FROM congress_attributes)")
And I have all of Congress’s mentions of one another ready to go. Phew!
All I did today was get those connections setup, get some data in data frames for R to use, and then draw some rudimentary graphs like this one:
I’m glad to see output, but I’m confused about why my isolate deleting functions didn’t work. Here’s how I tried to delete isolates:
mention_graph_no_iso <- delete.vertices(mention_graph, V(mention_graph)[degree(mention_graph)==0])
But I still see isolates in my graph. In fact, this one is even messier:
UPDATE:
The isolates weren’t in the graph object, but I forgot to rerun the layout after removing them. So, once I did that, I got a less messy graph (see below). I also cleaned up my code by moving the deleting isolates code to a function. I got the original function online but can’t find the page. Will post the URL here when I do. I made a small change to the function, and here it is:
delete.isolates <- function(graph, mode = 'all') {
isolates <- which(degree(graph, mode = mode) == 0)
delete.vertices(graph, isolates)
}