The twitteR package, released back in 2010, has long provided the means to access and analyze your Twitter social network data with R. But until recently, there hasn't been anything comparable for the Facebook social network. But now, thanks to Pablo Barbera, there is the RFacebook package which provides a collection of R functions to access data from your Facebook social network.
To use RFacebook, you first need to sign up for a Facebook developer account, which is quick and easy as long as you already have a Facebook profile. JulianHi provides an excellent step-by-step tutorial on getting started with RFacebook, including setting up your Facebook app and generating the authentition token that will be necessary for using the RFacebook functions.
Once you're authenticated, you can use the RFacebook functions to query your friends list and get information about your friends (and their connections with your other friends). I used the code below to query my Facebook friends, and used the igraph package to draw my social network:
require(Rfacebook) load("fb_oauth.Rd") ## load my previously saved authentication token me <- getUsers("me", token=fb_oauth) my_friends <- getFriends(token=fb_oauth, simplify=TRUE) my_friends_info <- getUsers(my_friends$id, token=fb_oauth, private_info=TRUE) my_network <- getNetwork(fb_oauth, format="adj.matrix") singletons <- rowSums(my_network)==0 # friends who are friends with me alone require(igraph) my_graph <- graph.adjacency(my_network[!singletons,!singletons]) layout <- layout.drl(my_graph,options=list(simmer.attraction=0)) plot(my_graph, vertex.size=2, #vertex.label=NA, vertex.label.cex=0.5, edge.arrow.size=0, edge.curved=TRUE,layout=layout)
I removed the singletons from the chart below to make it simpler, by excluding friends were friends with me but none of my other friends.
I chose not to include my friend's names in the chart, but the clusters it generates are good representations of my various social circles. The isolated group in the top-right is my childhood friends from Australia, who don't know any of my friends in the rest of the world. Other isolated clusters are my friends from the UK, work and R-related friends, and friends from California. The biggest cluster is my main social network from Seattle. It's quite impressive how just using the friend relationships (the adjacency graph), my "natural" social circles appear. I'm sure you coud do more with the additional informational available, which includes the birthday, location, profile picture and relationship status of your friends. You can only access information you could see on facebook.com, and even then only a subset: you can only access information about people you are friends with (even if they have public profiles), and you can't see your friends' entire social network, only the part you are only friends with. Still, it's a rich data source to play with, and I'm sure additional capabilities will be exposed in the RFacebook API as time goes on.
If you want to try out RFacebook yourself, get started at the link below.
Julianhi's Blog: Analyzing Facebook with R