Skip to content

Instantly share code, notes, and snippets.

@simecek
Created January 18, 2012 11:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save simecek/1632567 to your computer and use it in GitHub Desktop.
Save simecek/1632567 to your computer and use it in GitHub Desktop.
Facebook Friendship Graph Continued
require(pixmap)
# download small profile picture of each friend
dir.create("photos")
for (i in 1:length(friends.id))
download.file(paste("http://graph.facebook.com", friends.id[i], "picture", sep="/"),
destfile=paste("photos/",friends.id[i],".jpg",sep=""))
system('for i in `ls photos/*.jpg`; do j=${i%.*}; convert $j.jpg $j.pnm; done', wait=TRUE)
# customized node plotting function
makeNodeDrawFunction <- function(x) {
force(x)
function(node, ur, attrs, radConv) {
photo <- read.pnm(paste("photos/", x, ".pnm", sep=""))
nc <- getNodeCenter(node)
addlogo(photo, c(getX(nc)-25, getX(nc)+25), c(getY(nc)-25, getY(nc)+25))
}
}
drawFuns <- apply(as.array(friends.id), 1, makeNodeDrawFunction)
# a graph with photos
pdf(file="facebook2.pdf", width=25, height=25)
attrs <- list(node=list(shape="box", width=0.75, height=0.75))
plot(g, "neato", attrs=attrs, drawNode=drawFuns)
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment