<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>OUseful.Info, the blog... &#187; The Race to the F1 2012 Drivers&#8217; Championship &#8211; Initial Sketches</title>
	<atom:link href="http://blog.ouseful.info/2012/11/16/the-race-to-the-f1-2012-drivers-championship/feed/?withoutcomments=1" rel="self" type="application/rss+xml" />
	<link>http://blog.ouseful.info</link>
	<description>Trying to find useful things to do with emerging technologies in open education</description>
	<lastBuildDate>Wed, 19 Jun 2013 09:24:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.ouseful.info' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>OUseful.Info, the blog... &#187; The Race to the F1 2012 Drivers&#8217; Championship &#8211; Initial Sketches</title>
		<link>http://blog.ouseful.info</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.ouseful.info/osd.xml" title="OUseful.Info, the blog..." />
	<atom:link rel='hub' href='http://blog.ouseful.info/?pushpress=hub'/>
		<item>
		<title>The Race to the F1 2012 Drivers&#8217; Championship &#8211; Initial Sketches</title>
		<link>http://blog.ouseful.info/2012/11/16/the-race-to-the-f1-2012-drivers-championship/</link>
		<comments>http://blog.ouseful.info/2012/11/16/the-race-to-the-f1-2012-drivers-championship/#comments</comments>
		<pubDate>Fri, 16 Nov 2012 23:59:13 +0000</pubDate>
		<dc:creator>Tony Hirst</dc:creator>
				<category><![CDATA[Rstats]]></category>
		<category><![CDATA[ddj]]></category>
		<category><![CDATA[f1datajunkie]]></category>

		<guid isPermaLink="false">http://blog.ouseful.info/?p=8986</guid>
		<description><![CDATA[In part inspired by the chart described in The electoral map sans the map, I thought I&#8217;d start mulling over a quick sketch showing the race to the 2012 Formula One Drivers&#8217; Championship. The chart needs to show tension somehow, so in this first really quick and simple rough sketch, you really do have to [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ouseful.info&#038;blog=325417&#038;post=8986&#038;subd=ouseful&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In part inspired by the chart described in <a href="http://junkcharts.typepad.com/junk_charts/2012/11/the-electoral-map-sans-the-map.html">The electoral map sans the map</a>, I thought I&#8217;d start mulling over a quick sketch showing the race to the 2012 Formula One Drivers&#8217; Championship.</p>
<p>The chart needs to show tension somehow, so in this first really quick and simple rough sketch, you really do have to put yourself in the graph and start reading it from left to right:</p>
<p><a href="http://ouseful.files.wordpress.com/2012/11/f1-2012-race-to-champ-rnd-18.png"><img src="http://ouseful.files.wordpress.com/2012/11/f1-2012-race-to-champ-rnd-18.png?w=700" alt="" title="f1 2012 race to champ rnd 18"   class="alignnone size-full wp-image-8988" /></a></p>
<p>The data is pulled in from the <a href="http://ergast.com/mrd/">Ergast API</a> as JSON data, which is then parsed and visualised using R:</p>
<pre class="brush: r; title: ; notranslate">require(RJSONIO)
require(ggplot2)

#initialise a data frame
champ &lt;- data.frame(round=numeric(),
                 driverID=character(), 
                 position=numeric(), points=numeric(),wins=numeric(),
                 stringsAsFactors=FALSE)

#This is a fudge at the moment - should be able to use a different API call to 
#get the list of races to date, rather than hardcoding latest round number
for (j in 1:18){
  resultsURL=paste(&quot;http://ergast.com/api/f1/2012/&quot;,j,&quot;/driverStandings&quot;,&quot;.json&quot;,sep='')
  print(resultsURL)
  results.data.json=fromJSON(resultsURL,simplify=FALSE)
  rd=results.data.json$MRData$StandingsTable$StandingsLists[[1]]$DriverStandings
  for (i in 1:length(rd)){
    champ=rbind(champ,data.frame(round=j, driverID=rd[[i]]$Driver$driverId,
                               position=as.numeric(as.character(rd[[i]]$position)),
                                points=as.numeric(as.character(rd[[i]]$points)),
                                                  wins=as.numeric(as.character(rd[[i]]$wins)) ))
  }
}
champ

#Horrible fudge - should really find a better way of filtering?
test2=subset(champ,( driverID=='vettel' | driverID=='alonso' | driverID=='raikkonen'|driverID=='webber' | driverID=='hamilton'|driverID=='button' ))

#Really rough sketch, in part inspired by http://junkcharts.typepad.com/junk_charts/2012/11/the-electoral-map-sans-the-map.html
ggplot(test2)+geom_line(aes(x=round,y=points,group=driverID,col=driverID))+labs(title=&quot;F1 2012 - Race to the Championship&quot;)

#I wonder if it would be worth annotating the chart with labels explaining any DNF reasons at parts where points stall?</pre>
<p>So, that&#8217;s the quickest and dirtiest chart I could think of &#8211; where to take this next? One way would be to start making the chart look cleaner; another possibility would be to start looking at adding labels, highlights, and maybe pushing all but ALO and VET into the background? (GDS do some nice work in this vein, eg <a href="http://digital.cabinetoffice.gov.uk/2012/11/12/updating-performance-dashboard/">Updating the GOV.UK Performance Dashboard</a>; this StoryTellingWithData <a href="http://www.storytellingwithdata.com/2012/11/to-stack-or-not-to-stack.html">post on stacked bar charts</a> also has some great ideas about how to make simple, clean and effective use of text and highlighting&#8230;).</p>
<p>Let&#8217;s try cleaning it up a little, and then highlight the championship contenders?</p>
<p><a href="http://ouseful.files.wordpress.com/2012/11/f1-2012-race-cleaner.png"><img src="http://ouseful.files.wordpress.com/2012/11/f1-2012-race-cleaner.png?w=700" alt="" title="f1 2012 race cleaner"   class="alignnone size-full wp-image-8996" /></a></p>
<pre class="brush: r; title: ; notranslate">test3=subset(test,( driverID=='vettel' | driverID=='alonso' ))
test4=subset(test,( driverID=='raikkonen'|driverID=='webber' | driverID=='hamilton'|driverID=='button' ))

ggplot(test4) + geom_line(aes(x=round,y=position,group=driverID),col='lightgrey') + geom_line(data=test3,aes(x=round,y=position,group=driverID,col=driverID)) + labs(title=&quot;F1 2012 - Race to the Championship&quot;)
</pre>
<p>Hmm&#8230; I&#8217;m not sure about those colours? Maybe use Blue for VET and Red for ALO?</p>
<p><a href="http://ouseful.files.wordpress.com/2012/11/f1-chanps-redblue.png"><img src="http://ouseful.files.wordpress.com/2012/11/f1-chanps-redblue.png?w=700" alt="" title="f1 chanps redblue"   class="alignnone size-full wp-image-8998" /></a></p>
<p>I really hacked the path to this &#8211; there must be a cleaner way?!</p>
<pre class="brush: r; title: ; notranslate">ggplot(test4)+geom_line(aes(x=round,y=points,group=driverID),col='lightgrey') + geom_line(data=subset(test3,driverID=='vettel'),aes(x=round,y=points),col='blue') + geom_line(data=subset(test3,driverID=='alonso'),aes(x=round,y=points),col='red') + labs(title=&quot;F1 2012 - Race to the Championship&quot;)</pre>
<p>Other chart types are possible too, I suppose? Such as something in the style of a lap chart?</p>
<p><a href="http://ouseful.files.wordpress.com/2012/11/f1-2012-race-chart.png"><img src="http://ouseful.files.wordpress.com/2012/11/f1-2012-race-chart.png?w=700" alt="" title="f1 2012 race chart"   class="alignnone size-full wp-image-8992" /></a></p>
<pre class="brush: r; title: ; notranslate">ggplot(test2)+geom_line(aes(x=round,y=position,group=driverID,col=driverID))+labs(title=&quot;F1 2012 - Race to the Championship&quot;)</pre>
<p>Hmmm&#8230; Just like the first sketch, this one is cluttered and confusing too&#8230; How about if we clean it as above to highlight just the contenders?</p>
<p><a href="http://ouseful.files.wordpress.com/2012/11/f1-2012-race-lapchart-style-cleaner.png"><img src="http://ouseful.files.wordpress.com/2012/11/f1-2012-race-lapchart-style-cleaner.png?w=700" alt="" title="f1 2012 race lapchart style cleaner"   class="alignnone size-full wp-image-8997" /></a></p>
<pre class="brush: r; title: ; notranslate">ggplot(test4) + geom_line(aes(x=round,y=points,group=driverID),col='lightgrey') + geom_line(data=test3,aes(x=round,y=points,group=driverID,col=driverID)) + labs(title=&quot;F1 2012 - Race to the Championship&quot;)</pre>
<p>A little cleaner, maybe? And with the colour tweak:</p>
<p><a href="http://ouseful.files.wordpress.com/2012/11/f1-2102-champ-lapchart-redblue.png"><img src="http://ouseful.files.wordpress.com/2012/11/f1-2102-champ-lapchart-redblue.png?w=700" alt="" title="f1 2102 champ lapchart redblue"   class="alignnone size-full wp-image-9000" /></a></p>
<pre class="brush: r; title: ; notranslate">ggplot(test4) + geom_line(aes(x=round,y=position,group=driverID),col='lightgrey') + geom_line(data=subset(test3,driverID=='vettel'),aes(x=round,y=position),col='blue') + geom_line(data=subset(test3,driverID=='alonso'),aes(x=round,y=position),col='red') + labs(title=&quot;F1 2012 - Race to the Championship&quot;)</pre>
<p>Something that really jumps out at me in this chart are the gridlines &#8211; they really need fixing? But what would be best to show?</p>
<p>Hmm, before we do that, how about an animation? (Does WordPress.com allow animated gifs?)</p>
<p><a href="http://ouseful.files.wordpress.com/2012/11/animation.gif"><img src="http://ouseful.files.wordpress.com/2012/11/animation.gif?w=700" alt="" title="animation"   class="alignnone size-full wp-image-9004" /></a></p>
<p>Here&#8217;s the code (it requires the <tt>animation</tt> package):</p>
<pre class="brush: r; title: ; notranslate">library(animation)
race.ani= function(...) {
  for (i in 1:18) {
    g=ggplot(subset(test3, round&lt;=i)) + geom_line(aes(x=round,y=position,group=driverID),col='lightgrey')+geom_line(data=subset(test3,driverID=='vettel' &amp; round&lt;=i),aes(x=round,y=position),col='blue')+geom_line(data=subset(test3,driverID=='alonso' &amp; round &lt;=i),aes(x=round,y=position),col='red')+labs(title=&quot;F1 2012 - Race to the Championship&quot;)+xlim(1,18)
    print(g)
  }
}
saveMovie(race.ani(), interval = 0.4, outdir = getwd())</pre>
<p>And for the other chart:</p>
<p><a href="http://ouseful.files.wordpress.com/2012/11/animation1.gif"><img src="http://ouseful.files.wordpress.com/2012/11/animation1.gif?w=700" alt="" title="animation"   class="alignnone size-full wp-image-9005" /></a></p>
<p>Hmmm&#8230;</p>
<p>How&#8217;s about another sort of view  &#8211; the points difference between VET and ALO?</p>
<p><a href="http://ouseful.files.wordpress.com/2012/11/f1-2012-vet-v-alo.png"><img src="http://ouseful.files.wordpress.com/2012/11/f1-2012-vet-v-alo.png?w=700" alt="" title="f1 2012 vet v alo"   class="alignnone size-full wp-image-9007" /></a></p>
<pre class="brush: r; title: ; notranslate">alo=subset(test3,driverID=='alonso')
vet=subset(test3,driverID=='vettel')
colnames(vet)=c(&quot;round&quot;,&quot;driverID&quot;,&quot;vposition&quot;,&quot;vpoints&quot;,&quot;vwins&quot;)
colnames(alo)=c(&quot;round&quot;,&quot;driverID&quot;,&quot;aposition&quot;,&quot;apoints&quot;,&quot;awins&quot;)
cf= merge(alo,vet,by=c('round'))
ggplot(cf) + geom_bar( aes(x=round,y=vpoints-apoints,fill=(vpoints-apoints)&gt;0), stat='identity') + labs(title=&quot;F1 2012 Championship - VET vs ALO&quot;)</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ouseful.wordpress.com/8986/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ouseful.wordpress.com/8986/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ouseful.info&#038;blog=325417&#038;post=8986&#038;subd=ouseful&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.ouseful.info/2012/11/16/the-race-to-the-f1-2012-drivers-championship/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/abbd9f90565ce9ae4d065d93a81d8c03?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Tony Hirst</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/11/f1-2012-race-to-champ-rnd-18.png" medium="image">
			<media:title type="html">f1 2012 race to champ rnd 18</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/11/f1-2012-race-cleaner.png" medium="image">
			<media:title type="html">f1 2012 race cleaner</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/11/f1-chanps-redblue.png" medium="image">
			<media:title type="html">f1 chanps redblue</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/11/f1-2012-race-chart.png" medium="image">
			<media:title type="html">f1 2012 race chart</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/11/f1-2012-race-lapchart-style-cleaner.png" medium="image">
			<media:title type="html">f1 2012 race lapchart style cleaner</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/11/f1-2102-champ-lapchart-redblue.png" medium="image">
			<media:title type="html">f1 2102 champ lapchart redblue</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/11/animation.gif" medium="image">
			<media:title type="html">animation</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/11/animation1.gif" medium="image">
			<media:title type="html">animation</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/11/f1-2012-vet-v-alo.png" medium="image">
			<media:title type="html">f1 2012 vet v alo</media:title>
		</media:content>
	</item>
	</channel>
</rss>
