Created
January 18, 2012 11:33
-
-
Save simecek/1632567 to your computer and use it in GitHub Desktop.
Facebook Friendship Graph Continued
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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