Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(RCurl)
- library(compiler)
- library(igraph)
- library(tnet)
- su<-function(x) #Sort the unique entries
- return(sort(unique(x)))
- su<-cmpfun(su)
- #Function to read a data table from online
- read.sstab<-function(theurl, ...){
- #_theurl_ refers to the location of the data
- #_..._ are parameters passed onto read.table
- require(RCurl)
- outtab<-getURL(theurl, ssl.verifypeer=FALSE)
- outtab<-textConnection(outtab)
- outtab<-read.table(outtab, sep="\t", ...)
- return(outtab)
- }
- read.sstab<-cmpfun(read.sstab)
- #Download the most brutal data and name its parts
- metal.bands.df<-read.sstab("http://pastebin.com/raw.php?i=AA1SPz5K", header=TRUE, skip=4, as.is=TRUE, stringsAsFactors=FALSE, strip.white=TRUE, na.strings=c("NA", ""))
- colnames(metal.bands.df)[c(1,2)]<-c("group", "member")
- rm(read.sstab)
- #Some members exit a band and later reunite, a band sometimes disassembles and later reforms
- #For our purposes here, we're going to ignore the time dimension
- #The missing data kind of sucks for it, too.
- #We also switch the columns as members form groups
- non.dupes<-which(duplicated(paste(metal.bands.df$group, metal.bands.df$member, sep="*"))==FALSE)
- metal.bands.df<-metal.bands.df[non.dupes,c("member", "group")]
- metal.bands.df$member<-gsub("&", "&", metal.bands.df$member, fixed=TRUE)
- metal.bands.df$group<-gsub("&", "&", metal.bands.df$group, fixed=TRUE)
- #Retrieve the names for both members and groups.
- #Though a mighty package, tnet doesn't do labels, only integers.
- #_all.metal.names_ will be legend.
- all.metal.names<-unique(c(su(metal.bands.df$member), su(metal.bands.df$group)))
- metal.bands.df$member<-match(metal.bands.df$member, all.metal.names)
- metal.bands.df$group<-match(metal.bands.df$group, all.metal.names)
- #Ignore the abyss that is metal's missing data
- miss.rows<-which((is.na(metal.bands.df$member) | is.na(metal.bands.df$group))==TRUE)
- metal.bands.df<-metal.bands.df[-miss.rows,]
- metal.bands.tn<-list(member.group=as.tnet(metal.bands.df, type="binary two-mode tnet"), group.member=as.tnet(metal.bands.df[,c("group", "member")], type="binary two-mode tnet"))
- rm(non.dupes, miss.rows)
- #Spawn an igraph object
- metal.ig<-graph.data.frame(metal.bands.df[,c("member","group")], directed=FALSE)
- #"Alice Cooper" and other bands using only a member's full name are coded as bands, not musicians.
- #Some metal gods are just so epic they count as multiple people and one at the same time.
- V(metal.ig)$type<-V(metal.ig)$name%in%metal.bands.df$group
- V(metal.ig)$color<-rev(rainbow(2, s=.80, alpha=.80))[1+V(metal.ig)$type]
- V(metal.ig)$shape<-ifelse(V(metal.ig)$type, "square", "circle")
- V(metal.ig)$name<-all.metal.names[as.numeric(V(metal.ig)$name)]
- metal.comps<-clusters(metal.ig)
- other.comps<-which(metal.comps$csize>=26)[-1]
- other.comps.csize<-metal.comps$csize[other.comps]
- names(other.comps.csize)<-other.comps
- other.comps.csize<-sort(other.comps.csize, decreasing=TRUE)
- #sum(other.comps.csize)/vcount(metal.ig) #About 4% of the actors in the network
- other.comps.bands<-sapply(names(other.comps.csize), function(x) return(sum(V(metal.ig)$type[which(metal.comps$membership==x)])))
- other.comps.musicians<-sapply(names(other.comps.csize), function(x) return(sum(!V(metal.ig)$type[which(metal.comps$membership==x)])))
- other.comps.bandnames<-sapply(names(other.comps.csize), function(x) return(paste(V(metal.ig)$name[which((metal.comps$membership==x)&(V(metal.ig)$type))], collapse="; ")))
- other.comps.csize<-data.frame(n=other.comps.csize, bands=other.comps.bands, musicians=other.comps.musicians, band.names=other.comps.bandnames)
- rm(other.comps.bands, other.comps.musicians, other.comps.bandnames)
- cat("\n Percent of Bands: ", round(100*sum(other.comps.csize$bands)/sum(V(metal.ig)$type)), "%\n", sep="")
- cat("\n Percent of Musicians: ", round(100*sum(other.comps.csize$musicians)/sum(V(metal.ig)$type==FALSE)), "%\n", sep="")
- print(other.comps.csize)
- #Plot Dillinger Escape Plan and Tanner Wayne
- #These two should have ties to Mike Patton and Underoath, connecting them to the giant component
- miss.edges<-c(239, 760)
- miss.edges<-lapply(miss.edges, function(x){g<-induced.subgraph(metal.ig, which(metal.comps$membership==x)); g.lo<-layout.kamada.kawai(g, params=list(niter=5000, sigma=vcount(g)/16)); V(g)$x<-g.lo[,1]; V(g)$y<-g.lo[,2]; return(g)})
- png("Miss.edges.png", height=3, width=6, res=600, units="in", pointsize=8)
- par(mfrow=c(1,2))
- lapply(1:2, function(x) return(plot(miss.edges[[x]], vertex.size=10, vertex.label.cex=.45, vertex.label.color="black", vertex.label.family="sans", margin=.05)))
- dev.off()
- plot(induced.subgraph(metal.ig, which(metal.comps$membership%in%c(239, 760))), vertex.size=3, vertex.label.cex=.4, vertex.label.family="sans")
- #Plot the Japanese visual kei, OC metalcore, and Christian metal acts
- #Eighteen Visions should have a tie to Burn Halo through James Stephen Hart. Does not connect them to the giant component, though.
- #Whitecross has additional members, including at least one in King James.
- niche.comps<-c(221, 172, 30)
- names(niche.comps)<-c("Japanese Visual\nKei Metal", "Orange County Straight\nEdge Metalcore", "Christian Metal")
- niche.comps<-lapply(niche.comps, function(x){g<-induced.subgraph(metal.ig, which(metal.comps$membership==x)); g.lo<-layout.kamada.kawai(g, params=list(niter=5000, sigma=vcount(g)/16)); V(g)$x<-g.lo[,1]; V(g)$y<-g.lo[,2]; return(g)})
- png("Niche.Comps.png", height=3, width=9, res=600, units="in", pointsize=8)
- par(mfrow=c(1,3))
- lapply(1:3, function(x) return(plot(niche.comps[[x]], vertex.size=5, vertex.label.cex=.75, vertex.label.color="black", vertex.label.family="sans", margin=.05, main=names(niche.comps)[[x]])))
- dev.off()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement