Getting ggplot2 to work with igraph

One common criticism of the otherwise excellent ggplot2 is that it doesn’t come with network visualisation capability. Network vis is so popular at the moment that it seems like a bit of a big omission; but network data is also quite unique in terms of structure (and the layout algorithms would need implementing) so I can see why it hasn’t been integrated.

Moritz Marbach has a great post explaining how to easily get ggplot2 up and running with network data. It was still one of the top hits on Google when I checked it out recently for a project. However the post is from 2011 so is getting a little dated – it uses the sna package rather than igraph (which seems to be becoming a standard for network science) and also has a few deprecated ggplot2 commands in it. So I thought I’d add a bit of an update here to the code.

As Marbach explains the secret to getting ggplot2 to draw networks is quite simple: get a network analysis package to give you a list of nodes, edges, and node layout information as a series of X,Y coordinates. Then you can simply plot the nodes with geom_point and the edges with geom_segment. Put together it looks something like this:

library(igraph)

g = read.graph("a-network.gml", format="gml")

#get the node coordinates
plotcord <- data.frame(layout.fruchterman.reingold(g))
colnames(plotcord) = c("X1","X2")

#get edges, which are pairs of node IDs
edgelist <- get.edgelist(g)

#convert to a four column edge data frame with source and destination coordinates
edges <- data.frame(plotcord[edgelist[,1],], plotcord[edgelist[,2],])
colnames(edges) <- c("X1","Y1","X2","Y2")

ggplot() + geom_segment(aes(x=X1, y=Y1, xend = X2, yend = Y2), data=edges, size = 0.5, colour="grey") + geom_point(aes(X1, X2), data=plotcord)

Output:

igraph-ggplot2

OK it still needs some work! But anyone familiar with ggplot2 can do the rest.

The History of Social News

I am giving a presentation tomorrow at the IJPP conference here in Oxford. It’s being hosted by the Reuters Institute who are world leaders in the study of contemporary news organisations, and I’m really excited to be going.

Together with Scott Hale I am giving a presentation on the “history” of social news. We have an 8 year long dataset (2002-2010) consisting of links to millions of news articles which we have used to trace the beginnings of social media news sharing. We are interested to know whether the types of news being shared have changed over time as social media platforms have massified; we’re also interested in looking at whether site design changes (such as bringing in sharing buttons) have had a major impact.

Twitter - Facebook Comparison

The project is at an early stage but the results are pretty interesting so far (to me). To give one tidbit, we show that in this large scale dataset there is only a weak correlation between sharing on Twitter and Facebook at the article level, with Twitter tending to share more sports news than Facebook (see image).

The real component of virtual learning

Monica Bulger, Cristobal Cobo and I have a new paper out in Information, Communication and Society where we investigate real world meetings organised by MOOC users. These meetings are sort of contradictory as of course one of the advantages of MOOCs is that they are online and can be accessed anywhere without the need to travel; yet lots of users are kind of building in this face to face component themselves, all over the world (see the map). We asked whether this was because they felt they were missing something from the MOOC experience (and were therefore sort of recreating classrooms) or whether it was more of an excuse to network and socialise (hence recreating the after school social experience). We find evidence for both motivations though the former is stronger.

Meetup - Map

These meetings show important potential to fix one of the strongest criticisms of MOOCs, which is that they are only for the really self-motivated and that many people drop out: by creating local learning communities, perhaps motivation can increase. Yet this also cuts against the idea of global learning: it was clear, for obvious reasons, that most meetings take place in big cities in the developed world. Those in urban areas or developing countries simply have less people to meet with.

Public Policy, Big Data and Smart Cities

I have just got back from the International Conference on Public Policy in Milan, where I was attending a stream of internet and public policy panels, as well as presenting a paper on explaining open data outcomes which I am currently working on together with some colleagues here at the OII. The conference itself was huge: in only it’s second year it attracted around 1,300 registrations, from across the policy sciences. Our sessions on the internet were quite well attended, though I didn’t feel like we attracted many people beyond those already interested in the internet.

ICPP2015

I acted as discussant on a couple of panels on big data, with a particularly interesting one on smart cities. I think the smart city field is where public policy and big data overlap most closely: using big data to govern the city has already captured a lot of attention in both academia and policy itself, with examples of initiatives such as the Mayor’s Office for Data Analytics in New York or the Centro de Operações in Rio de Janeiro. It’s interesting to see the potential these places have for improving existing administration

It’s also worth highlighting all the challenges to smart city development, from opening data to getting the right skills in place. This is probably the reason why large cities which have created these kind of data “nerve centres” are leading the way, because they can overcome these obstacles in a concentrated way with direct support from the hierarchy. They raise the interesting possibility, furthermore, that they will become not just supporters of policy execution, but places where policy is set and defined. That would be revolutionary.

New Paper in European Union Politics

I have just published a paper in European Union Politics, together with Diego Garzia, Joseph Lacey and Alex Trechsel of the EUI. The paper was the fruition of a long term research project examining potential ways of changing the European Parliament’s electoral system, focussed in particular on allowing people to vote for parties in any member state. It seems particularly relevant today when protest parties such as Syriza and Podemos attract support (and criticism) from well outside of their own borders.

The paper explores what would happen under conditions of such transnationalisation, examining both what types of people would be likely to vote “transnationally” and the extent to which overall levels of representation would improve. Great to have it in print.

Follow

Get every new post delivered to your Inbox.