Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Data collected by Moviegalaxies
- #Data distributed using Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported
- #I've read two of their datasets into Gephi and exported the data into Google Docs
- #The code below reads the data from Google Docs and returns iGraph "graph" objects.
- #Likewise, I've licensed my own derivative work using Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported
- #See http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US
- library(RCurl); library(igraph)
- read.sstab<-function(theurl){
- outtab<-getURL(theurl, ssl.verifypeer=FALSE)
- outtab<-textConnection(outtab)
- outtab<-read.table(outtab, sep="\t", header=TRUE, as.is=TRUE, stringsAsFactors=FALSE, strip.white=TRUE, quote="\"")
- return(outtab)
- }
- #The Big Lebowski
- #http://moviegalaxies.com/movies/download/125/The-Big-Lebowski
- bigl.nodes<-read.sstab("https://docs.google.com/spreadsheet/pub?key=0Ai--oOZQWBHSdDYtOEpUZ21FUWUyTEc2eXZSSm93TEE&single=true&gid=0&output=txt")
- bigl.edges<-read.sstab("https://docs.google.com/spreadsheet/pub?key=0Ai--oOZQWBHSdDYtOEpUZ21FUWUyTEc2eXZSSm93TEE&single=true&gid=1&output=txt")
- #Magnolia
- #http://moviegalaxies.com/movies/download/523/Magnolia
- mag.nodes<-read.sstab("https://docs.google.com/spreadsheet/pub?key=0Ai--oOZQWBHSdDYtOEpUZ21FUWUyTEc2eXZSSm93TEE&single=true&gid=2&output=txt")
- mag.edges<-read.sstab("https://docs.google.com/spreadsheet/pub?key=0Ai--oOZQWBHSdDYtOEpUZ21FUWUyTEc2eXZSSm93TEE&single=true&gid=3&output=txt")
- #BE WARNED that the Magnolia data contains errors in it. I don't know how MovieGalaxies collected their data. Presumably they wrote a program that scans movie scripts which contain typos and machines can't differentiate between some similar names. This dataset was not spot checked. The errors include:
- #"CLAUDIA" and "CLAUIDA" are listed as two separate nodes. They should be one; the second is a typo.
- #"JIMMY" and "JIMMY GATOR" are the same characters.
- #"YOUNG PHARAMCY KID" and "YOUNG PHARMACY KID" should be the same
- #I can't tell if "OFFICER" refers to a distinct character, one of the numbered officers, or "JIM KURRING"
- #"GET OUT" isn't the name of any character listed in IMDB.
- #There's a "DOC", "DOCTOR", and three characters with the title "DR". "DOC" should be separate from all three of the "DR" characters, however I'm unsure who "DOCTOR" refers to.
- #"DON" and "DONNIE" are the same character.
- #"STANELY" and "STANLEY" are the same character.
- #There's probably other errors in it.
- #The Big Lebowski's dataset looks clean to me.
- sstab2igraph<-function(theel, thenodes){
- theel$Source<-thenodes$Label[match(theel$Source, thenodes$Id)]
- theel$Target<-thenodes$Label[match(theel$Target, thenodes$Id)]
- theig<-graph.edgelist(as.matrix(theel[,c("Source", "Target")]), directed=FALSE)
- theig<-set.edge.attribute(theig, "weight", index=E(theig), theel$Weight)
- name2row<-match(thenodes$Label, V(theig)$name)
- #The attributes in _thenodes_ we're interested in start with "Eccentricity" until the end
- startcol<-which(colnames(thenodes)=="Eccentricity")
- for (i in startcol:ncol(thenodes))
- theig<-set.vertex.attribute(graph=theig, name=colnames(thenodes)[i], index=V(theig)[name2row], value=as.numeric(thenodes[,i]))
- return(theig)
- }
- bigl.ig<-sstab2igraph(bigl.edges, bigl.nodes)
- mag.ig<-sstab2igraph(mag.edges, mag.nodes)
- rm(read.sstab, bigl.edges, bigl.nodes, mag.edges, mag.nodes, sstab2igraph)
- #A nice looking plot of The Big Lebowski:
- #plot(bigl.ig, vertex.size=2*log(igraph::degree(bigl.ig)+1)*2, vertex.label.cex=log(igraph::degree(bigl.ig)+1)/3, edge.width=E(bigl.ig)$weight/2, vertex.label.family="sans", vertex.label.font=2, vertex.label.color="lightgrey", vertex.label.dist=.60, vertex.label.degree=4.7, vertex.color=rainbow(1, alpha=.75))
- #Degree distribution plot
- #par(fg="lightgrey", col.lab="lightgrey", col.axis="lightgrey", col.main="lightgrey", col.sub="lightgrey")
- #plot(ecdf(igraph::degree(bigl.ig)), main=expression(italic("The Big Lebowski")), xlab="Degree", ylab="Cumlative Proportion of Nodes", verticals=TRUE)
- #dev.off()
Advertisement
Add Comment
Please, Sign In to add comment