{"id":621,"date":"2012-12-11T20:36:01","date_gmt":"2012-12-11T20:36:01","guid":{"rendered":"http:\/\/rulesofreason.wordpress.com\/?p=621"},"modified":"2012-12-11T20:36:01","modified_gmt":"2012-12-11T20:36:01","slug":"music-network-visualization","status":"publish","type":"post","link":"http:\/\/re-design.dimiter.eu\/?p=621","title":{"rendered":"Music Network Visualization"},"content":{"rendered":"<p><em>Note: probably of interest only to the intersection of the readers who are into niche music genres and those interested in network visualization.<\/em><\/p>\n<p>My music interests have always been rather, hmm&#8230;, eclectic. Somehow IDM, ambient, darkwave, triphop, acid jazz, bossa nova, qawali, Mali blues and other more or less obscure genres have managed to\u00a0happily\u00a0co-exist in my music collection. The sheer diversity always invited the question whether there is some structure to the collection, or each genre is an island of its own. Sounds like a job for network visualization!<\/p>\n<p>Now, there are plenty of music network viz applications on the <a href=\"http:\/\/www.slideshare.net\/plamere\/using-visualizations-for-music-discovery\" target=\"_blank\">web<\/a>. But they don&#8217;t show <strong>my<\/strong> collection, and just seem unsatisfactory for various reasons. So I decided to craft my own visualization using <em>R<\/em> and <em>igraph.<\/em><\/p>\n<p>As a first step I collected for all artists in my <a href=\"http:\/\/last.fm\" target=\"_blank\">last.fm<\/a> library the artists that the site classifies as similar. So I piggyback on <a href=\"http:\/\/last.fm\" target=\"_blank\">last.fm<\/a>\u00a0for the network similarity measures. I also get info on the most-often used tag for the artist and the number of plays it has on the site. The rest is pretty straightforward as can be seen from the code.<\/p>\n<pre># Load the igraph and foreign packages (install if needed)\n<code>require(igraph)\nrequire(foreign)<\/code>\n<code>lastfm&lt;-read.csv(\"http:\/\/www.dimiter.eu\/Data_files\/lastfm_network_ad.csv\", header=T,  encoding=\"UTF-8\")<\/code> #Load the dataset\n\n<code>lastfm$include&lt;-ifelse(lastfm$Similar %in% lastfm$Artist==T,1,0)<\/code> #Index the links between artists in the library\n<code>lastfm.network&lt;-graph.data.frame(lastfm, directed=F)<\/code> #Import as a graph\n\n<code>last.attr&lt;-lastfm[-which(duplicated(lastfm$Artist)),c(5,3,4) ] <\/code>#Create some attributes\n<code>V(lastfm.network)[1:106]$listeners&lt;-last.attr[,2]\nV(lastfm.network)[107:length(V(lastfm.network))]$listeners&lt;-NA\nV(lastfm.network)[1:106]$tag&lt;-last.attr[,3]\nV(lastfm.network)[107:length(V(lastfm.network))]$tag&lt;-NA<\/code> #Attach the attributes to the artist from the library (only)\n<code>V(lastfm.network)$label.cex$tag&lt;-ifelse(V(lastfm.network)$listeners&gt;1200000, 1.4, \n                                    (ifelse(V(lastfm.network)$listeners&gt;500000, 1.2,\n                                            (ifelse(V(lastfm.network)$listeners&gt;100000, 1.1,\n                                                   (ifelse(V(lastfm.network)$listeners&gt;50000, 1, 0.8)))))))<\/code> #Scale the size of labels by the relative popularity\n\n<code>V(lastfm.network)$color&lt;-\"white\"<\/code> #Set the color of the dots\n<code>V(lastfm.network)$size&lt;-0.1<\/code> #Set the size of the dots\n<code>V(lastfm.network)$label.color&lt;-NA\nV(lastfm.network)[1:106]$label.color&lt;-\"white\"<\/code> #Only the artists from the library should be in white, the rest are not needed\n\n<code>E(lastfm.network)[ include==0 ]$color&lt;-\"black\" \nE(lastfm.network)[ include==1 ]$color&lt;-\"red\"<\/code> #Color edges between artists in the library red, the rest are not needed\n\n<code>fix(tkplot)<\/code> #Add manually to the function an argument for the background color of the canvas and set it to black (bg=black)\n\n<code>tkplot(lastfm.network, vertex.label=V(lastfm.network)$name, layout=layout.fruchterman.reingold,\n       canvas.width=1200, canvas.height=800)<\/code> #Plot the graph and adjust as needed<\/pre>\n<p>I plot the network with the <em>tkplot<\/em> command which allows for the manual adjustments necessary because many artist names get on top of each other in the initial plot. Because the export options of <em>tkplot<\/em> are limited I just took a print screen ( I know, I know, that&#8217;s kind of cheating ;-)), added the\u00a0tittle\u00a0in Photoshop and, voila, it&#8217;s done!<\/p>\n<p>[click to enlarge and explore]<br \/>\n<a href=\"https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/12\/my-music-netowrk.jpg\" target=\"_blank\"><img data-attachment-id=\"624\" data-permalink=\"http:\/\/re-design.dimiter.eu\/?attachment_id=624\" data-orig-file=\"https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/12\/my-music-netowrk.jpg?fit=1311%2C800\" data-orig-size=\"1311,800\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"my-music-netowrk\" data-image-description=\"\" data-medium-file=\"https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/12\/my-music-netowrk.jpg?fit=300%2C183\" data-large-file=\"https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/12\/my-music-netowrk.jpg?fit=1024%2C625\" loading=\"lazy\" class=\"alignnone size-medium wp-image-624\" alt=\"my-music-netowrk\" src=\"https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/12\/my-music-netowrk.jpg?resize=300%2C183\" width=\"300\" height=\"183\" srcset=\"https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/12\/my-music-netowrk.jpg?w=1311 1311w, https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/12\/my-music-netowrk.jpg?resize=300%2C183 300w, https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/12\/my-music-netowrk.jpg?resize=768%2C469 768w, https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/12\/my-music-netowrk.jpg?resize=1024%2C625 1024w, https:\/\/i1.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/12\/my-music-netowrk.jpg?resize=1200%2C732 1200w\" sizes=\"(max-width: 300px) 100vw, 300px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>Knowing intimately the artists in the graph, I can certify that the network definitely makes a lot of sense. I love the small clusters (Flying Louts, Andy Stott, Extrawelt and Claro Intelecto [minimal\/dub], or Anouar Brahem and Rabih Abou-Khalil [ethno jazz]) loosely connected to the rest of the network. And I love the fact that the boundary spanners are immediately obvious (e.g. Pink Martini between acid jazz and world music [<em>what a stupid label by the way<\/em>!], or Cesaria Evora between African and\u00a0Caribbean\u00a0music, or Portishead between brit-pop, trip-hop and darkwave, or Amon Tobin between trip-hop, electro and IDM). Even the different <em>world music<\/em> genres are close to each other but still unconnected. And somehow Banco De Gaya, the most ethno of all electronica in the library, ended up closest to the world\/ethno clusters. There are a few problems, like Depeche Mode, which get to be pulled from the opposite sides of the graph, but these are very few.<\/p>\n<p>Altogether, I have to admit I feel like a teenage dream of mine has finally been realized. But I realize the network is a rather personal thing (as it was meant to be) so I don&#8217;t expect many to get overly excited about it. Still, I would be glad to hear your comments or suggestions for extensions and improvements. And, if you were a good boy\/girl during the year, I could also consider visualizing <em>your<\/em> last.fm network as a present for the new year!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note: probably of interest only to the intersection of the readers who are into niche music genres and those interested in network visualization. My music interests have always been rather, hmm&#8230;, eclectic. Somehow IDM, ambient, darkwave, triphop, acid jazz, bossa nova, qawali, Mali blues and other more or less obscure genres have managed to\u00a0happily\u00a0co-exist in my music collection. The sheer diversity always invited the question whether there is some structure to the collection, or each genre is an island of its own. Sounds like a job for network visualization! Now, there are plenty of music network viz applications on the web. But they don&#8217;t show my collection, and just seem unsatisfactory for various reasons. So I decided to craft my own visualization using R and igraph. As a first step I collected for all artists in my last.fm library the artists that the site classifies as similar. So I piggyback on last.fm\u00a0for the network similarity measures. I also get info on the most-often used tag for the artist and the number of plays it has on the site. The rest is pretty straightforward as can be seen from the code. # Load the igraph and foreign packages (install if needed) require(igraph) require(foreign) lastfm&lt;-read.csv(&#8220;http:\/\/www.dimiter.eu\/Data_files\/lastfm_network_ad.csv&#8221;, header=T, encoding=&#8221;UTF-8&#8243;) #Load the dataset lastfm$include&lt;-ifelse(lastfm$Similar %in% lastfm$Artist==T,1,0) #Index the links between artists in the library lastfm.network&lt;-graph.data.frame(lastfm, directed=F) #Import as a graph last.attr&lt;-lastfm[-which(duplicated(lastfm$Artist)),c(5,3,4) ] #Create some attributes V(lastfm.network)[1:106]$listeners&lt;-last.attr[,2] V(lastfm.network)[107:length(V(lastfm.network))]$listeners&lt;-NA V(lastfm.network)[1:106]$tag&lt;-last.attr[,3] V(lastfm.network)[107:length(V(lastfm.network))]$tag&lt;-NA #Attach the attributes to the artist from the library (only) V(lastfm.network)$label.cex$tag&lt;-ifelse(V(lastfm.network)$listeners&gt;1200000, 1.4, (ifelse(V(lastfm.network)$listeners&gt;500000, 1.2, (ifelse(V(lastfm.network)$listeners&gt;100000, 1.1,&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"http:\/\/re-design.dimiter.eu\/?p=621\">Continue reading<span class=\"screen-reader-text\">Music Network Visualization<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[11,30,39],"tags":[322,373,374,423,424,425,426,439,539],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7g3hj-a1","jetpack-related-posts":[{"id":547,"url":"http:\/\/re-design.dimiter.eu\/?p=547","url_meta":{"origin":621,"position":0},"title":"Network visualization in R with the igraph package","date":"November 5, 2012","format":false,"excerpt":"In this post I showed a visualization of the organizational network of my department. Since several people asked for details how the plot has been produced, I will provide the code and some extensions below. The plot has been done entirely in R (2.14.01) with the help of the igraph\u2026","rel":"","context":"In &quot;Data visualization&quot;","img":{"alt_text":"","src":"https:\/\/i2.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/11\/org_network2.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":948,"url":"http:\/\/re-design.dimiter.eu\/?p=948","url_meta":{"origin":621,"position":1},"title":"Books on data visualization","date":"November 21, 2017","format":false,"excerpt":"Here is a compilation of new and classic books on data visualization: \u00a0 Scott Murray (2017)\u00a0Interactive Data Visualization for the Web\u00a0[amazon asin=1491921285&template=add to cart] Elijah Meeks (2017)\u00a0D3.Js in Action: Data Visualization with JavaScript\u00a0[amazon asin=1617294489&template=add to cart] Alberto Cairo (2016)\u00a0The Truthful Art: Data, Charts, and Maps for Communication\u00a0[amazon asin=0321934075&template=add to cart]\u2026","rel":"","context":"In &quot;Data visualization&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":531,"url":"http:\/\/re-design.dimiter.eu\/?p=531","url_meta":{"origin":621,"position":2},"title":"The hidden structure of (academic) organizations","date":"October 23, 2012","format":false,"excerpt":"All organizations have a 'deep' hidden structure based on the social interactions among its members which might or might not coincide with the official formal one. University departments are no exception - if anything, the informal alliances, affinities, and allegiances within academic departments are only too visible and salient. Network\u2026","rel":"","context":"In &quot;Network analysis&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/10\/social-network-bsk1.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":647,"url":"http:\/\/re-design.dimiter.eu\/?p=647","url_meta":{"origin":621,"position":3},"title":"New data source for political science researchers","date":"December 19, 2012","format":false,"excerpt":"Political Data Yearbook Interactive\u00a0is a new source for data on election results, turnout and government composition for all EU and some non-European countries. It is basically an online version of the yearbooks that ECPR printed as part of the European Journal for Political Research for many years now. The interactive\u2026","rel":"","context":"In &quot;Data visualization&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":287,"url":"http:\/\/re-design.dimiter.eu\/?p=287","url_meta":{"origin":621,"position":4},"title":"Hyperlinks","date":"February 3, 2012","format":false,"excerpt":"Science visualization challenge 2011 192 answers to the question 'What is your favorite deep, elegant, or beautiful explanation?' Higher education for the masses [commentary by Felix Salmon] Researchers feel pressure to cite superfluous papers","rel":"","context":"In &quot;Hyperlinks&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":439,"url":"http:\/\/re-design.dimiter.eu\/?p=439","url_meta":{"origin":621,"position":5},"title":"New tool for discourse network analysis","date":"April 11, 2012","format":false,"excerpt":"EJPR has just published an article introducing a new tool for 'discourse network analysis'. Using the tool, you can measure and visualize political discourses and the networks of actors affiliated to each discourse. One can study the actor congruence networks (based on the number of statements actors share), concept congruence\u2026","rel":"","context":"In &quot;Data visualization&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/re-design.dimiter.eu\/wp-content\/uploads\/2012\/04\/discourse-network.jpg?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=\/wp\/v2\/posts\/621"}],"collection":[{"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=621"}],"version-history":[{"count":0,"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=\/wp\/v2\/posts\/621\/revisions"}],"wp:attachment":[{"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=621"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/re-design.dimiter.eu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}