The underlying data wasn’t available. So I put on my graph-to-numbers glasses on and pulled out some data. Here it is in case you want to have a go.
I took on the first part of the challenge i.e. Can you think of a way to make this graph easier to read?
I hacked up the following version in R. It was a bit of a challenge to get it right given the constraints of fitting all the data and legend within a 290 x 300 image.
Do you think this is an improvement? Leave a comment below or in Nathan’s original post at http://flowingdata.com/2010/02/25/challenge-make-this-graph-easier-to-read/.
And here’s the R code:
#Read the file
#Reset the column name from United.States to United States; R replaces spaces in variable names with dots; you’ll see why below.
#Define our colour palette so that we can edit it in one place and refer to colours by index as shown below
#Start PNG device with the given constraints of 300×290 (boy that’s a small image!)
par(mar=c(2,2,3,1) #Small images call for small margins
,las=1) #For some reason, the default orientation (las=0) of the axis labels is parallel to the axis. This works OK for the X axis but makes it hard to read Y axis labels, so set to horizontal.
#Finally, the main plot command
,xaxt=”n” #Don’t draw default X axis; we’ll draw a custom one below.
,xaxs=”i” #X axis style (internal) just finds an axis with pretty labels that fits within the original data range. If you don’t use this then an extra space is added at the edges even if you set xlim
,yaxs=”i”#Style – Same reason as X Axis
,main=”Total government spending n(% of GDP by year)” #Got rid of ‘The shape of the beast’ for space constraints
,ylim=c(30,70) #Setting the top Y axis limits to allow space for the legend
,lwd=4 #Quite unusually high line width but good for improving visibility in a small graph.
#Custom X axis
axis(side=1 #That’s the bottom X axis side
,at=Year[2:16] #labels starting from 1996; using at=Year places the labels at odd years.
,labels=substr(Year[2:16],3,4)) #Instead of using the full year, use just 2 digits.
grid(lwd=0.4,lty=1,col=”#000000″) #Very faint grid to guide the eyes.
#Add the rest of the lines
#United States; Note we can’t use United States~Year because of the space between United and States. This calls for use of the data[[“variable name”]] notation.
#Lastly the legend
legend(“top” #Align it at the top in the center
,ncol=2 #Number of columns to spread the legend labels overs; 2 works best for our graph.
,col=pal #Make sure to use the same colour palette as the graph lines!
,bg=”#FFFFFF” #White background to make it merge with the plot background.
,inset=0.01) #Inset the legend so that it doesn’t quite touch the border of the plot.
dev.off() #Close the graphics device