<?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/"
	>

<channel>
	<title>FlowingData &#187; Statistical Visualization</title>
	<atom:link href="http://flowingdata.com/category/visualization/statistical-visualization/feed/" rel="self" type="application/rss+xml" />
	<link>http://flowingdata.com</link>
	<description>Strength in Numbers</description>
	<lastBuildDate>Thu, 11 Mar 2010 14:27:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<atom:link rel="next" href="http://flowingdata.com/category/visualization/statistical-visualization/feed/?page=2" />

		<item>
		<title>Canada: the country that pees together stays together</title>
		<link>http://flowingdata.com/2010/03/09/canada-the-country-that-pees-together-stays-together/</link>
		<comments>http://flowingdata.com/2010/03/09/canada-the-country-that-pees-together-stays-together/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 04:50:53 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[Statistical Visualization]]></category>

		<guid isPermaLink="false">http://flowingdata.com/?p=6017</guid>
		<description><![CDATA[<a href="http://flowingdata.com/2010/03/09/canada-the-country-that-pees-together-stays-together/" title="Canada: the country that pees together stays together"><img src="http://flowingdata.com/wp-content/uploads/yapb_cache/flush_game.5va6dz765ugw8880gswc80w8o.22qwr5zijcckg48go4wowg88o.th.png" width="545" height="373" alt="Canada: the country that pees together stays together" ></a>EPCOR, the water utility company that runs the fountains up in Edmonton, Canada released this graph yesterday. It's water consumption during the Olympic gold medal hockey game, overlaying consumption of the previous day. How much do Canadians love their hockey? A lot.
The first period ends. Time to pee. The second period ends. Time to pee. [...]]]></description>
			<content:encoded><![CDATA[<a href="http://flowingdata.com/2010/03/09/canada-the-country-that-pees-together-stays-together/" title="Canada: the country that pees together stays together"><img src="http://flowingdata.com/wp-content/uploads/yapb_cache/flush_game.5va6dz765ugw8880gswc80w8o.22qwr5zijcckg48go4wowg88o.th.png" width="545" height="373" alt="Canada: the country that pees together stays together" ></a><p>EPCOR, the water utility company that runs the fountains up in Edmonton, Canada released <a href="http://www.patspapers.com/blog/item/what_if_everybody_flushed_at_once_Edmonton_water_gold_medal_hockey_game/">this graph</a> yesterday. It's water consumption during the Olympic gold medal hockey game, overlaying consumption of the previous day. How much do Canadians love their hockey? A lot.</p>
<p>The first period ends. Time to pee. The second period ends. Time to pee. The third period ends. Time to pee. Consumption goes way down when Canada wins and during the medal ceremony. </p>
<p>Finally, when it's all said and done, the rest of the country can relieve itself, figuratively and literally.</p>
<p>[via <a href="http://contrarian.ca/2010/03/09/the-nation-that-pees-together/">contrarian</a> | thanks, @<a href="http://twitter.com/statpumpkin/status/10225922494">statpumpkin</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://flowingdata.com/2010/03/09/canada-the-country-that-pees-together-stays-together/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Challenge: make this graph easier to read</title>
		<link>http://flowingdata.com/2010/02/25/challenge-make-this-graph-easier-to-read/</link>
		<comments>http://flowingdata.com/2010/02/25/challenge-make-this-graph-easier-to-read/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 17:03:12 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[Discussion]]></category>
		<category><![CDATA[Statistical Visualization]]></category>
		<category><![CDATA[Featured]]></category>

		<guid isPermaLink="false">http://flowingdata.com/?p=5602</guid>
		<description><![CDATA[The Economist discusses the return of big government and includes this graph showing total government spending as a percentage of Gross Domestic Product. Is there a better way to represent the time series?]]></description>
			<content:encoded><![CDATA[<p class=" img-right"><img src="http://flowingdata.com/wp-content/uploads/2010/02/CFB772.gif" alt="" title="Total government spending as percent of GDP" width="290" height="299" class="alignnone size-full wp-image-5603" /></p>
<p><em>The Economist</em> discusses the <a href="http://www.economist.com/world/international/displaystory.cfm?story_id=15328727">return of big government</a> and includes this graph showing total government spending as a percentage of Gross Domestic Product. We see a dip in 2000 and a big jump this past year.</p>
<p>The trouble is that the country labels are cluttered. If you read them left to right, you get mixed up initially. Keep your eyes left and move top to bottom, and you might be okay.</p>
<h2>The Challenge</h2>
<p>Can you think of a way to make this graph easier to read? Is there a better way to represent the time series?</p>
<p>One catch: you have to work within the size limitation of 290 pixels wide and 300 pixels tall. It's an easy fix with unlimited space. But what can you do when space is scarce? Leave your thoughts in the comments below.</p>
<p>P.S. I was looking for the data this graph uses but got tired of using the OECD stat browser, so we'll just have to use our imagination for this one.</p>
<p>[Thanks, Justin]</p>
<p><strong>Update:</strong> Here's <a href="http://flowingdata.com/wp-content/uploads/2010/02/gdp.xls">GDP (sans spending) by country</a> from 1995 to 2008 if anyone would like to take a wack [thanks, <a href="http://periscopic.com">Kim</a>].</p>
]]></content:encoded>
			<wfw:commentRss>http://flowingdata.com/2010/02/25/challenge-make-this-graph-easier-to-read/feed/</wfw:commentRss>
		<slash:comments>76</slash:comments>
		</item>
		<item>
		<title>An Exploration of Biological Records</title>
		<link>http://flowingdata.com/2010/02/25/an-exploration-of-biological-records/</link>
		<comments>http://flowingdata.com/2010/02/25/an-exploration-of-biological-records/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 08:24:08 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[Statistical Visualization]]></category>
		<category><![CDATA[homeviz]]></category>

		<guid isPermaLink="false">http://flowingdata.com/?p=5402</guid>
		<description><![CDATA[<a href="http://flowingdata.com/2010/02/25/an-exploration-of-biological-records/" title="An Exploration of Biological Records"><img src="http://flowingdata.com/wp-content/uploads/yapb_cache/taxon.5kod4fzt5mcccw8wg4k048wgw.22qwr5zijcckg48go4wowg88o.th.png" width="545" height="276" alt="An Exploration of Biological Records" ></a>The Natural Science Museum of Barcelona has a growing database of 50,000 records of specimens collected over the past 150 years. Bestiario explores this data in their biodiversity treemap and geographical map. 

The cool thing about the treemap is that you can zoom in iteratively through the Phylums, Classes, Orders, Families, etc. The interaction is [...]]]></description>
			<content:encoded><![CDATA[<a href="http://flowingdata.com/2010/02/25/an-exploration-of-biological-records/" title="An Exploration of Biological Records"><img src="http://flowingdata.com/wp-content/uploads/yapb_cache/taxon.5kod4fzt5mcccw8wg4k048wgw.22qwr5zijcckg48go4wowg88o.th.png" width="545" height="276" alt="An Exploration of Biological Records" ></a><p>The Natural Science Museum of Barcelona has a growing database of 50,000 records of specimens collected over the past 150 years. <a href="http://bestiario.org/">Bestiario</a> explores this data in their <a href="http://arbre.bioexplora.cat/">biodiversity treemap</a> and <a href="http://mapa.bioexplora.cat/">geographical map</a>. </p>
<p><img src="http://flowingdata.com/wp-content/uploads/2010/02/mapped-545x325.png" alt="" title="mapped" width="545" height="325" class="alignnone size-medium wp-image-5404" /></p>
<p>The cool thing about the treemap is that you can zoom in iteratively through the Phylums, Classes, Orders, Families, etc. The interaction is similar to NYT's <a href="http://flowingdata.com/2010/02/01/obamas-budget-proposal-and-incorrect-forecasts/">treemap</a> that showed Obama's budget proposal from earlier this month, except there are a lot more levels, so you zoom, and then you zoom some more.</p>
<p>[Thanks, Jose]</p>
]]></content:encoded>
			<wfw:commentRss>http://flowingdata.com/2010/02/25/an-exploration-of-biological-records/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Road to Recovery &#8211; Is the Recovery Act working?</title>
		<link>http://flowingdata.com/2010/02/17/road-to-recovery-is-the-recovery-act-working/</link>
		<comments>http://flowingdata.com/2010/02/17/road-to-recovery-is-the-recovery-act-working/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 08:08:57 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[Discussion]]></category>
		<category><![CDATA[Statistical Visualization]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[homeviz]]></category>

		<guid isPermaLink="false">http://flowingdata.com/?p=5496</guid>
		<description><![CDATA[The Obama administration just posted a graph showing monthly job loss from December up to last month. It looks like the Recovery Act has had a major impact, but does this graph really tell the full story? Something tells me there's more to see. Discuss.]]></description>
			<content:encoded><![CDATA[<a href="http://flowingdata.com/2010/02/17/road-to-recovery-is-the-recovery-act-working/" title="Road to Recovery &#8211; Is the Recovery Act working?"><img src="http://flowingdata.com/wp-content/uploads/yapb_cache/jobs_graph_large_feb10.c3h0r1lbq7ks0cckook8wskcs.22qwr5zijcckg48go4wowg88o.th.png" width="545" height="317" alt="Road to Recovery &#8211; Is the Recovery Act working?" ></a><p>The Obama administration just posted <a href="http://my.barackobama.com/page/content/recoveryanniversary/">a graph</a> showing monthly job loss from December 2007 (Bush in red) up to last month. Discuss.</p>
<p>[via @<a href="http://twitter.com/nickbilton/status/9216396528">nickbilton</a>]</p>
<p><strong>Update:</strong> There's a video version now [via <a href="http://infosthetics.com/archives/2010/03/obama_loves_infographics.html">infosthetics</a>].</p>
<p><object width="480" height="295"><param name="movie" value="http://www.youtube.com/v/jWmUnU7HS-I&hl=en_US&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/jWmUnU7HS-I&hl=en_US&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://flowingdata.com/2010/02/17/road-to-recovery-is-the-recovery-act-working/feed/</wfw:commentRss>
		<slash:comments>81</slash:comments>
		</item>
		<item>
		<title>Build Online Visualization for Free with Tableau Public</title>
		<link>http://flowingdata.com/2010/02/16/build-online-visualization-for-free-with-tableau-public/</link>
		<comments>http://flowingdata.com/2010/02/16/build-online-visualization-for-free-with-tableau-public/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 09:07:28 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[Online Applications]]></category>
		<category><![CDATA[Statistical Visualization]]></category>

		<guid isPermaLink="false">http://flowingdata.com/?p=5418</guid>
		<description><![CDATA[
Tableau Software, popular for making data more accessible, mainly in the business sector, just opened up with Tableau Public. The application is similar in spirit to other online data applications like Many Eyes and Swivel. It lets you share data and visualizations online. However, Tableau Public doesn't have a central portal or a place to [...]]]></description>
			<content:encoded><![CDATA[<p class='img-right'><img src="http://flowingdata.com/wp-content/uploads/2010/02/tableau-logo-pubilc.png" alt="" title="tableau pubilc" width="245" height="57" class="alignnone size-full wp-image-5439" /></p>
<p><a href="http://tableausoftware.com/flowingdata">Tableau Software</a>, popular for making data more accessible, mainly in the business sector, just opened up with <a href="http://www.tableausoftware.com/public/">Tableau Public</a>. The application is similar in spirit to other online data applications like <a href="http://many-eyes.com">Many Eyes</a> and <a href="http://swivel.com">Swivel</a>. It lets you share data and visualizations online. However, Tableau Public doesn't have a central portal or a place to browse data. Rather it's focused on letting you explore data and stitch modules together on your desktop and then embed your findings on a website or blog.</p>
<p>For example, below is an interactive hosted on Tableau Public and made available online. Those who use Tableau Desktop should be familiar with the layout. You've got a map up top linked to the the time series on the bottom. Filters on the right let you focus on specific parts of the data.</p>
<p><script type="text/javascript" src="http://public.tableausoftware.com/javascripts/api/viz_v1.js"></script><object class="tableauViz" width="484" height="719" style="display:none;"><param name="name" value="USTopCitiesOverTime/PopOverTime480" /><param name="toolbar" value="yes" /></object><noscript>Pop Over Time 480 <br /><a href="#"><img alt="Pop Over Time 480 " src="http://public.tableausoftware.com/static/images/USTopCitiesOverTime-PopOverTime480_rss.png" height="100%" /></a></noscript>
<div style="width:484px;height:22px;padding:0px 10px 0px 0px; margin-top: -6px; color:black;font:normal 8pt verdana,helvetica,arial,sans-serif;"></div>
<h2>Hot it Works</h2>
<p>Like I said, Tableau Public works a little differently than you're used to. You do everything on your own computer first and when you're ready to share, the data and visualization is hosted on Tableau's servers. Copy and paste some javascript to your site and there you go. Easy stuff.</p>
<h2>Thoughts</h2>
<p>The main trouble with this, and you might have noticed this already, is that the interaction is kind of slow, because everything renders on the server and then is sent back to your browser. So it takes a second or two for every click to process (for me, at least).</p>
<p>For comparison, if we embedded something from Many Eyes, the applet and data are loaded locally, so the visualization interaction is much faster. </p>
<p>Speed can be fixed though. Loading times aside, this is a big shift for Tableau, and it'll be fun to see where it goes from here. It's especially good news for the non-programmer crowd that's interested in data. With the price tag of free, there's nothing to lose and a lot to play with.</p>
<h2>Your Thoughts</h2>
<p>What do you think? <a href="http://www.tableausoftware.com/public/">Try for yourself</a> and post your thoughts in the comments below. I'd be especially interested in hearing what regular Tableau users think about the product. How does it compare?</p>
<p>Disclosure: Tableau Software is a FlowingData sponsor.</p>
]]></content:encoded>
			<wfw:commentRss>http://flowingdata.com/2010/02/16/build-online-visualization-for-free-with-tableau-public/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>An Easy Way to Make a Treemap</title>
		<link>http://flowingdata.com/2010/02/11/an-easy-way-to-make-a-treemap/</link>
		<comments>http://flowingdata.com/2010/02/11/an-easy-way-to-make-a-treemap/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 08:35:53 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[Statistical Visualization]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Featured]]></category>

		<guid isPermaLink="false">http://flowingdata.com/?p=5299</guid>
		<description><![CDATA[Back in 1990, Ben Shneiderman, of the University of Maryland, wanted to visualize what was going on in his always-full hard drive. He wanted to know what was taking up so much space. Given the hierarchical structure of directories and files, he first tried a tree diagram. It got too big too fast to be [...]]]></description>
			<content:encoded><![CDATA[<p>Back in 1990, <a href="http://www.cs.umd.edu/~ben/">Ben Shneiderman</a>, of the University of Maryland, <a href="http://www.cs.umd.edu/hcil/treemap-history/index.shtml">wanted to visualize</a> what was going on in his always-full hard drive. He wanted to know what was taking up so much space. Given the hierarchical structure of directories and files, he first tried a <a href="http://en.wikipedia.org/wiki/Tree_%28data_structure%29">tree diagram</a>. It got too big too fast to be useful though. Too many nodes. Too many branches.</p>
<p>The <a href="http://en.wikipedia.org/wiki/Treemapping">treemap</a> was his solution. It's an area-based visualization where the size of each rectangle represents a metric since made popular by Martin Wattenberg's <a href="http://www.smartmoney.com/map-of-the-market/">Map of the Market</a> and Marcos Weskamp's <a href="http://newsmap.jp/">newsmap</a>.</p>
<p>Here's a really easy way to make your own treemap in just a couple lines of code. We're looking to make something like this:</p>
<p><img class="alignnone size-full wp-image-5311" title="treemap-revised" src="http://flowingdata.com/wp-content/uploads/2010/02/treemap-revised.gif" alt="" width="545" height="446" /></p>
<h3>Step 0. Download R</h3>
<p>Like before, we're going to use R, so you'll want to get it before going any further. Download it for <a href="http://cran.stat.ucla.edu/bin/windows/base/">Windows</a>, <a href="http://cran.stat.ucla.edu/bin/macosx/">Mac</a>, or <a href="http://cran.stat.ucla.edu/bin/linux/">Linux</a>. Don't let the out-dated site full you. You can get a lot done with the free software.</p>
<h3>Step 1. Load the Data</h3>
<p>We'll use data covering a hundred popular posts on FlowingData. Here it is in <a href="http://datasets.flowingdata.com/post-data.txt">CSV format</a>. You don't have to download it though. We'll just load it directly into R. The main thing to take note of is what is there. There's post id, number of views, number of comments, and category.</p>
<p>Okay, let's load it into R using <code>read.csv()</code>:</p>
<p><code>data &lt;- read.csv("http://datasets.flowingdata.com/post-data.txt")</code></p>
<p><img class="alignnone size-medium wp-image-5333" title="step1" src="http://flowingdata.com/wp-content/uploads/2010/02/step1-545x477.png" alt="" width="545" height="477" /></p>
<p>Easy enough. We just used the <code>read.csv()</code> function to load data from a URL. If your data is on your computer, you could also do something like <code>data &lt;- read.csv("post-data.txt")</code>. Just make sure the data file is in your current working directory, which you can change via the "Miscellaneous" menu.</p>
<h3>Step 2. Load the Portfolio Library</h3>
<p>Only a few more lines of code, and you've got a treemap. It's so easy, because we're going to use the <code>portfolio</code> library in R. First, you have to install it. You can either install the library via the "Package Installer" or you can do it through the command line. Let's do the latter. Type this in the console to install <code>portfolio</code>:</p>
<p><code>install.packages("portfolio")</code></p>
<p>Once installed, load it into R:</p>
<p><code>library(portfolio)</code></p>
<h3>Step 3. Make the Treemap</h3>
<p>It's time to make the treemap with <code>map.market()</code>. Type this in the console:</p>
<p><code>map.market(id=data$id, area=data$views, group=data$category, color=data$comments, main="FlowingData Map")</code></p>
<p>Tada. You should get something like this:</p>
<p><img class="alignnone size-medium wp-image-5314" title="original" src="http://flowingdata.com/wp-content/uploads/2010/02/original-545x471.png" alt="" width="545" height="471" /></p>
<p>To sum up, we did this with four lines of code:</p>
<p><code>data &lt;- read.csv("http://datasets.flowingdata.com/post-data.txt")<br />
install.packages("portfolio")<br />
library(portfolio)<br />
map.market(id=data$id, area=data$views, group=data$category, color=data$comments, main="FlowingData Map")</code></p>
<h3>Step 4. Customize</h3>
<p>Now maybe you want to modify something like color. The cool thing about R is that you can see the code for all the functions, edit it, and then use your customized version. If the green and red scheme isn't for you or you don't care about the positive/negative cutoff, then you can change the code to do that. I won't go into detail, but if you type <code>map.market</code> in the console, you'll see the function. You can change color or cutoff around lines 36-46.</p>
<p>For example, you can do a black and white color scheme:</p>
<p><img class="alignnone size-medium wp-image-5340" title="black-white" src="http://flowingdata.com/wp-content/uploads/2010/02/black-white-545x453.png" alt="" width="545" height="453" /></p>
<p>I was alright with the green for this, so I saved it as a PDF and then loaded it into Illustrator as usual. I numbed the green some, cleaned up the labels with a new font and layout, and updated the legend.</p>
<p><img class="alignnone size-full wp-image-5343" title="treemap-revised" src="http://flowingdata.com/wp-content/uploads/2010/02/treemap-revised1.gif" alt="" width="545" height="446" /></p>
<p>And there you go - a treemap with just a few lines of code in our all-trusty R. Rinse and repeat with your own data.</p>
]]></content:encoded>
			<wfw:commentRss>http://flowingdata.com/2010/02/11/an-easy-way-to-make-a-treemap/feed/</wfw:commentRss>
		<slash:comments>47</slash:comments>
		</item>
		<item>
		<title>Obama&#8217;s Budget Proposal and Incorrect Forecasts</title>
		<link>http://flowingdata.com/2010/02/01/obamas-budget-proposal-and-incorrect-forecasts/</link>
		<comments>http://flowingdata.com/2010/02/01/obamas-budget-proposal-and-incorrect-forecasts/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 20:28:08 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[Statistical Visualization]]></category>

		<guid isPermaLink="false">http://flowingdata.com/?p=5190</guid>
		<description><![CDATA[<a href="http://flowingdata.com/2010/02/01/obamas-budget-proposal-and-incorrect-forecasts/" title="Obama&#8217;s Budget Proposal and Incorrect Forecasts"><img src="http://flowingdata.com/wp-content/uploads/yapb_cache/tree.cah9rc1txggkos04koko0ggck.22qwr5zijcckg48go4wowg88o.th.png" width="545" height="317" alt="Obama&#8217;s Budget Proposal and Incorrect Forecasts" ></a>President Obama announced his 2011 budget proposal. How does it compare to last year's budget? Shan Carter and Amanda Cox of The New York Times compare the two plans. Red indicates a decrease in the percentage of the budget dedicated to the respective area, and green is for growth. Zoom in for a better view [...]]]></description>
			<content:encoded><![CDATA[<a href="http://flowingdata.com/2010/02/01/obamas-budget-proposal-and-incorrect-forecasts/" title="Obama&#8217;s Budget Proposal and Incorrect Forecasts"><img src="http://flowingdata.com/wp-content/uploads/yapb_cache/tree.cah9rc1txggkos04koko0ggck.22qwr5zijcckg48go4wowg88o.th.png" width="545" height="317" alt="Obama&#8217;s Budget Proposal and Incorrect Forecasts" ></a><p>President Obama announced his 2011 budget proposal. How does it compare to last year's budget? Shan Carter and Amanda Cox of The New York Times <a href="http://www.nytimes.com/interactive/2010/02/01/us/budget.html">compare the two plans</a>. Red indicates a decrease in the percentage of the budget dedicated to the respective area, and green is for growth. Zoom in for a better view of the smaller areas.</p>
<p>Big decreases for Medicaid grants, veteran benefits, and unemployment insurance. Major increase for education, Medicare, and administration of justice.</p>
<p>This of course takes budget forecasting into account, which Ms. Cox shows isn't all that accurate sometimes.</p>
<p><a href="http://www.nytimes.com/interactive/2010/02/02/us/politics/20100201-budget-porcupine-graphic.html"><img src="http://flowingdata.com/wp-content/uploads/2010/02/forecast-545x332.png" alt="" title="forecast" width="545" height="332" class="alignnone size-medium wp-image-5191" /></a></p>
<p>[via @<a href="http://twitter.com/nytgraphics">nytgraphics</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://flowingdata.com/2010/02/01/obamas-budget-proposal-and-incorrect-forecasts/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to Make a Heatmap &#8211; a Quick and Easy Solution</title>
		<link>http://flowingdata.com/2010/01/21/how-to-make-a-heatmap-a-quick-and-easy-solution/</link>
		<comments>http://flowingdata.com/2010/01/21/how-to-make-a-heatmap-a-quick-and-easy-solution/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 08:50:44 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Statistical Visualization]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://flowingdata.com/?p=4884</guid>
		<description><![CDATA[How do you make a heatmap? This came from kerimcan in the FlowingData forums, and krees followed up with a couple of good links on how to do them in R. It really is super easy.]]></description>
			<content:encoded><![CDATA[<p>How do you make a heatmap? This came from <a href="http://forums.flowingdata.com/profile/kerimcan">kerimcan</a> in the FlowingData <a href="http://forums.flowingdata.com/topic/advice-for-some-time-series-data-visualization">forums</a>, and <a href="http://periscopic.com/">krees</a> followed up with a couple of good links on how to do them in R. It really is super easy. Here's how to make a heatmap, with just a few lines of code, like this.</p>
<p><img src="http://flowingdata.com/wp-content/uploads/2010/01/nba_heatmap_revised.png" alt="" title="nba_heatmap_revised" width="545" height="861" class="alignnone size-full wp-image-4915" /></p>
<h3>The Heatmap</h3>
<p>In case you don't know what a heatmap is, it's basically a table that has colors in place of numbers. Colors correspond to the level of the measurement. Each column can be a different metric like above, or it can be all the same like <a href="http://online.wsj.com/article/SB125993225142676615.html#articleTabs%3Dinteractive">this one</a>. It's useful for finding highs and lows and sometimes, patterns.</p>
<p>On to the tutorial.</p>
<h3>Step 0. Download R</h3>
<p>We're going to use <a href="http://r-project.org">R</a> for this. It's a statistical computing language and environment, and it's free. Get it for <a href="http://cran.stat.ucla.edu/bin/windows/base/">Windows</a>, <a href="http://cran.stat.ucla.edu/bin/macosx/">Mac</a>, or <a href="http://cran.stat.ucla.edu/bin/linux/">Linux</a>. It's a simple one-click install for Windows and Mac. I've never tried Linux.</p>
<p>Did you download and install R? Okay, let's move on. </p>
<h3>Step 1. Load the data</h3>
<p>Like all visualization, you should start with the data. No data? No visualization for you.</p>
<p>For this tutorial, we'll use NBA basketball statistics from last season that I downloaded from <a href="http://databasebasketball.com">databaseBasketball</a>. I've made it available <a href="http://datasets.flowingdata.com/ppg2008.csv">here</a> as a CSV file. You don't have to download it though. R can do it for you.</p>
<p>I'm assuming you started R already. You should see a blank window.</p>
<p><img src="http://flowingdata.com/wp-content/uploads/2010/01/1Rconsole-545x473.png" alt="" title="1Rconsole" width="545" height="473" class="alignnone size-medium wp-image-4895" /></p>
<p>Now we'll load the data using <code>read.csv()</code>.</p>
<p><code>nba <- read.csv("http://datasets.flowingdata.com/ppg2008.csv", sep=",")<br />
</code></p>
<p>We've read a CSV file from a URL and specified the field separator as a comma. The data is stored in <code>nba</code>.</p>
<p>Type <code>nba</code> in the window, and you can see the data.</p>
<p><img src="http://flowingdata.com/wp-content/uploads/2010/01/2load-545x473.png" alt="" title="2load" width="545" height="473" class="alignnone size-medium wp-image-4897" /></p>
<h3>Step 2. Sort data</h3>
<p>The data is sorted by points per game, greatest to least. Let's make it the other way around so that it's least to greatest.</p>
<p><code>nba <- nba[order(nba$PTS),]<br />
</code></p>
<p>We could just as easily chosen to order by assists, blocks, etc. </p>
<h3>Step 3. Prepare data</h3>
<p>As is, the column names match the CSV file's header. That's what we want.</p>
<p>But we also want to name the rows by player name instead of row number, so type this in the window:</p>
<p><code>row.names(nba) <- nba$Name<br />
</code></p>
<p>Now the rows are named by player, and we don't need the first column anymore so we'll get rid of it:</p>
<p><code>nba <- nba[,2:20]<br />
</code></p>
<h3>Step 4. Prepare data, again</h3>
<p>Are you noticing something here? It's important to note that a lot of visualization involves gathering and preparing data. Rarely, do you get data exactly how you need it, so you should expect to do some data munging before the visuals. Anyways, moving on.</p>
<p>The data was loaded into a data frame, but it has to be a data matrix to make your heatmap. The difference between a frame and a matrix is not important for this tutorial. You just need to know how to change it.</p>
<p><code>nba_matrix <- data.matrix(nba)<br />
</code></p>
<h3>Step 5. Make a heatmap</h3>
<p>It's time for the finale. In just one line of code, build the heatmap (remove the line break):</p>
<p><code>nba_heatmap <- heatmap(nba_matrix, Rowv=NA, Colv=NA, <br />
        col = cm.colors(256), scale="column", margins=c(5,10))<br />
</code></p>
<p>You should get a heatmap that looks something like this:</p>
<p><img src="http://flowingdata.com/wp-content/uploads/2010/01/3heatmap-545x565.png" alt="" title="3heatmap" width="545" height="565" class="alignnone size-medium wp-image-4902" /></p>
<h3>Step 6. Color selection</h3>
<p>Maybe you want a different color scheme. Just change the argument to <code>col</code>, which is <code>cm.colors(256)</code> in the line of code we just executed. Type <code>?cm.colors</code> for help on what colors R offers. For example, you could use more heat-looking colors:</p>
<p><code>nba_heatmap <- heatmap(nba_matrix, Rowv=NA, Colv=NA, <br />
        col = heat.colors(256), scale="column", margins=c(5,10))<br />
</code></p>
<p><img src="http://flowingdata.com/wp-content/uploads/2010/01/4heat-545x564.png" alt="" title="4heat" width="545" height="564" class="alignnone size-medium wp-image-4913" /></p>
<p>For the heatmap at the beginning of this post, I used the <a href="http://cran.r-project.org/web/packages/RColorBrewer/index.html">RColorBrewer library</a>. Really, you can choose any color scheme you want. The <code>col</code> argument accepts any vector of hexidecimal-coded colors.</p>
<h3>Step 7. Clean it up - optional</h3>
<p>If you're using the heatmap to simply see what your data looks like, you can probably stop. But if it's for a report or presentation, you'll probably want to clean it up. You can fuss around with the options in R or you can save the graphic as a PDF and then import it into your favorite illustration software.</p>
<p>I personally use <a href="http://www.amazon.com/gp/product/B001EUDJWQ?ie=UTF8&tag=flowingdata-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=B001EUDJWQ">Adobe Illustrator</a>, but you might prefer <a href="http://www.inkscape.org/">Inkscape</a>, the open source (free) solution. Illustrator is kind of expensive, but you can probably find an old version on the cheap. I still use CS2. Adobe's up to CS4 already.</p>
<p>For the final basketball graphic, I used a blue color scheme from RColorBrewer and then lightened the blue shades, added white border, changed the font, and organized the labels in Illustrator. Voila.</p>
<p><img src="http://flowingdata.com/wp-content/uploads/2010/01/nba_heatmap_revised.png" alt="" title="nba_heatmap_revised" width="545" height="861" class="alignnone size-full wp-image-4915" /></p>
<p>Rinse and repeat to use with your own data. Have fun heatmapping.</p>
]]></content:encoded>
			<wfw:commentRss>http://flowingdata.com/2010/01/21/how-to-make-a-heatmap-a-quick-and-easy-solution/feed/</wfw:commentRss>
		<slash:comments>56</slash:comments>
		</item>
		<item>
		<title>Build Statistical Graphics Online With ggplot2</title>
		<link>http://flowingdata.com/2009/12/22/build-statistical-graphics-online-with-ggplot2/</link>
		<comments>http://flowingdata.com/2009/12/22/build-statistical-graphics-online-with-ggplot2/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 08:08:49 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[Online Applications]]></category>
		<category><![CDATA[Statistical Visualization]]></category>

		<guid isPermaLink="false">http://flowingdata.com/?p=4417</guid>
		<description><![CDATA[<a href="http://flowingdata.com/2009/12/22/build-statistical-graphics-online-with-ggplot2/" title="Build Statistical Graphics Online With ggplot2"><img src="http://flowingdata.com/wp-content/uploads/yapb_cache/ggplot_online.bsfhuy0azvccoswsgosg4ookw.22qwr5zijcckg48go4wowg88o.th.png" width="545" height="335" alt="Build Statistical Graphics Online With ggplot2" ></a>Statisticians are generally behind the times when it comes to online applications. There are a lot out-dated Java applets and really rough attempts at getting R, a statistical computing environment, in some useful form through a browser. So imagine my surprise when I tried this tool by Jeroen Ooms, a visiting scholar at UCLA Statistics. [...]]]></description>
			<content:encoded><![CDATA[<a href="http://flowingdata.com/2009/12/22/build-statistical-graphics-online-with-ggplot2/" title="Build Statistical Graphics Online With ggplot2"><img src="http://flowingdata.com/wp-content/uploads/yapb_cache/ggplot_online.bsfhuy0azvccoswsgosg4ookw.22qwr5zijcckg48go4wowg88o.th.png" width="545" height="335" alt="Build Statistical Graphics Online With ggplot2" ></a><p>Statisticians are generally behind the times when it comes to online applications. There are a lot out-dated Java applets and really rough attempts at getting <a href="http://www.r-project.org/">R</a>, a statistical computing environment, in some useful form through a browser. So imagine my surprise when I tried <a href="http://www.yeroon.net/ggplot2/">this tool</a> by Jeroen Ooms, a visiting scholar at UCLA Statistics. </p>
<p>It actually works pretty well, and for a prototype, it isn't half bad.</p>
<h3>Statistical Graphics as Layers</h3>
<p>The engine behind Jeroen's tool is Hadley Wickham's <a href="http://had.co.nz/ggplot/">ggplot2</a>, an R implementation of of Leland Wilkinson's <a href="http://www.amazon.com/gp/product/0387245448?ie=UTF8&tag=flowingdata-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=0387245448">Grammar of Graphics</a>. Yes, it's a big chain of events.</p>
<p>Those who use Adobe products, like Illustrator or Photoshop, are familiar with the idea of layers in your graphics.</p>
<p>Without going into all the details, the main idea is that statistical graphics are made up of layers. There's the data, axes, and the plot. You can do this in R with the ggplot2 library, or, with this tool, you can upload data and specify the layers through the clickety interface.</p>
<p>Here's a short demo of ggplot in action:</p>
<p><object width="480" height="295"><param name="movie" value="http://www.youtube.com/v/7XGN6OSCq6E&hl=en_US&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/7XGN6OSCq6E&hl=en_US&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://flowingdata.com/2009/12/22/build-statistical-graphics-online-with-ggplot2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to Make an Interactive Area Graph with Flare</title>
		<link>http://flowingdata.com/2009/12/09/how-to-make-an-interactive-area-graph/</link>
		<comments>http://flowingdata.com/2009/12/09/how-to-make-an-interactive-area-graph/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 08:55:33 +0000</pubDate>
		<dc:creator>Nathan</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Statistical Visualization]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://flowingdata.com/?p=4165</guid>
		<description><![CDATA[You've seen the NameExplorer from the Baby Name Wizard by Martin Wattenberg. It's an interactive area chart that lets you explore the popularity of names over time. Search by clicking on names or typing in a name in the prompt. It's simple. It's sexy. Everybody loves it.
This is a step-by-step guide on how to make [...]]]></description>
			<content:encoded><![CDATA[<p>You've seen the <a href="http://www.babynamewizard.com/voyager">NameExplorer</a> from the Baby Name Wizard by Martin Wattenberg. It's an interactive area chart that lets you explore the popularity of names over time. Search by clicking on names or typing in a name in the prompt. It's simple. It's sexy. Everybody loves it.</p>
<p>This is a step-by-step guide on how to make a similar visualization in Actionscript/Flash with your own data and how to customize the design for whatever you need. We're after last week's <a href="http://projects.flowingdata.com/america/spending/">graphic</a> on consumer spending:</p>
<p><img class="alignnone size-full wp-image-4183" title="consumer spending" src="http://flowingdata.com/wp-content/uploads/2009/12/spending.png" alt="consumer spending" width="545" height="578" /></p>
<h3>Audience</h3>
<p>This tutorial is for people with at least a little bit of programming experience. I'll try to make it as straightforward as possible, but the concepts might be a little hard to grasp if you've never written a line of code. Just a heads up. Of course it never hurts to try.</p>
<p>If you don't care about customization or integration into an application and don't mind putting your data in the public domain, you could also just dump your data into Many Eyes, and use the <a href="http://manyeyes.alphaworks.ibm.com/manyeyes/page/Stack_Graph.html">Stack Graph</a>.</p>
<h3>Get Adobe Flex Builder</h3>
<p>Like I said, this is all in Actionscript, so before we start anything, I strongly recommend you get <a href="http://www.amazon.com/gp/product/B0014A4G5U?ie=UTF8&amp;tag=flowingdata-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B0014A4G5U">Adobe Flex Builder</a> if you don't already have it. You can buy it, get a trial version from the Adobe site, or if you're in education, you can <a href="https://freeriatools.adobe.com/flex/">get it for free</a>.</p>
<p>There are <a href="http://opensource.adobe.com/wiki/display/flexsdk/Downloads">ways</a> to compile Actionscript without Flex Builder, but they are more complicated.</p>
<h3>Working With Flare</h3>
<p>Luckily you don't have to start from scratch. In fact, most of the work has already been done for you using Jeffrey Heer's <a href="http://flare.prefuse.org/">Flare visualization toolkit</a>. It's an Actionscript library. We're going to work off one of the sample applications: <a href="http://flare.prefuse.org/apps/job_voyager">JobVoyager</a>. Once you get your development environment setup, it's just a matter of switching in your data, and then customizing the look and feel. </p>
<p>Okay, let's get started (finally).</p>
<h3>Step 0. Download and import Flare</h3>
<p><a href="http://flare.prefuse.org/download">Download</a> the most recent version of Flare, and then unpack the contents into your working directory.</p>
<p>Open Flex Builder. You should see something like this:</p>
<p><img class="alignnone size-medium wp-image-4205" title="Flex Builder Window" src="http://flowingdata.com/wp-content/uploads/2009/12/Picture-1-545x375.png" alt="Flex Builder Window" width="545" height="375" /></p>
<p>Right click on the Flex Navigator (left-hand side) and click on "Import..." You'll get a popup that looks like this:</p>
<p><img class="alignnone size-medium wp-image-4206" title="Picture 2" src="http://flowingdata.com/wp-content/uploads/2009/12/Picture-2-545x567.png" alt="Picture 2" width="545" height="567" /></p>
<p>Select "Existing Projects into Workspace" and click "Next." Browse to where you put the Flare files. Select the "flare" directory, and then make sure "flare" is checked in the project window.</p>
<p><img class="alignnone size-medium wp-image-4208" title="Picture 3" src="http://flowingdata.com/wp-content/uploads/2009/12/Picture-3-545x567.png" alt="Picture 3" width="545" height="567" /></p>
<p>Do the same thing with the "flare.apps" folder. Your Flex Builder window should look like this once you've expanded the flare.apps/flare/apps/ and click on JobVoyager.as.</p>
<p><img class="alignnone size-medium wp-image-4213" title="JobVoyager Code" src="http://flowingdata.com/wp-content/uploads/2009/12/Picture-5-545x375.png" alt="JobVoyager Code" width="545" height="375" /></p>
<p>If you clicked the run button right now (the green button with the white play triangle top left), you should see the working <a href="http://flare.prefuse.org/apps/job_voyager">JobVoyager</a>. Get that working, and you're done with the hardest part.</p>
<h3>Step 1. Update the data source</h3>
<p>Let's dive into the code now so you can adapt the visualization to your own data and customize the aesthetics. Again, we're going to adapt this code to <a href="http://projects.flowingdata.com/america/spending/expenditures.txt">consumer spending data</a> to make last week's graphic.</p>
<p><img class="alignnone size-full wp-image-4183" title="consumer spending" src="http://flowingdata.com/wp-content/uploads/2009/12/spending.png" alt="consumer spending" width="545" height="578" /></p>
<p>First we need to change the data source. This is specified on <code>line 57</code>.</p>
<pre class="actionscript"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">_url</span>:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;http://flare.prefuse.org/data/jobs.txt&quot;</span>;
&nbsp;</pre>
<p>Change the <code>_url</code> to point at the spending data, which like <code>jobs.txt</code>, is also a tab-delimited file. The first column is <code>year</code>, the second <code>category</code>, and the last column is <code>expenditure</code>:</p>
<pre class="actionscript"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">_url</span>:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;http://datasets.flowingdata.com/expenditures.txt&quot;</span>
&nbsp;</pre>
<p>Now the file will read in our spending data instead of for jobs. Easy stuff so far.</p>
<h3>Step 2. Change the years</h3>
<p>The next two lines, <code>line 58</code> and <code>59</code> are the column names, or in this case, the distinct years that job data was available. It's by decade from 1850 to 2000. We could make things more robust by finding the years in the loaded data, but since the data isn't changing we can same some time and explicitly specify the years.</p>
<p>Our expenditures data is annual from 1984 to 2008. We'll change lines 58-59 accordingly.</p>
<pre class="actionscript"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _cols:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1984</span>,<span style="color: #cc66cc;">1985</span>,<span style="color: #cc66cc;">1986</span>,<span style="color: #cc66cc;">1987</span>,<span style="color: #cc66cc;">1988</span>,<span style="color: #cc66cc;">1989</span>,<span style="color: #cc66cc;">1990</span>,<span style="color: #cc66cc;">1991</span>,
		<span style="color: #cc66cc;">1992</span>,<span style="color: #cc66cc;">1993</span>,<span style="color: #cc66cc;">1994</span>,<span style="color: #cc66cc;">1995</span>,<span style="color: #cc66cc;">1996</span>,<span style="color: #cc66cc;">1997</span>,<span style="color: #cc66cc;">1998</span>,<span style="color: #cc66cc;">1999</span>,
		<span style="color: #cc66cc;">2000</span>,<span style="color: #cc66cc;">2001</span>,<span style="color: #cc66cc;">2002</span>,<span style="color: #cc66cc;">2003</span>,<span style="color: #cc66cc;">2004</span>,<span style="color: #cc66cc;">2005</span>,<span style="color: #cc66cc;">2006</span>,<span style="color: #cc66cc;">2007</span>,<span style="color: #cc66cc;">2008</span><span style="color: #66cc66;">&#93;</span>;
&nbsp;</pre>
<h3>Step 3. Data headers</h3>
<p>Next we need to change references to the data headers. The original data file (<code>jobs.txt</code>) has four columns: <code>year</code>, <code>occupation</code>, <code>people</code> and <code>sex</code>. Our spending data only has three columns: <code>year</code>, <code>category</code>, and <code>expenditure</code>. We have to adapt the code to this new data structure.</p>
<p>Luckily, it's pretty easy. The <code>year</code> column is the same, so we just need to change any <code>people</code> references to <code>expenditure</code> (vertical axis) and any <code>occupation</code> references to <code>category</code> (the layers). Finally, we'll remove all uses of gender.</p>
<p>At <code>line 74</code> the data is reshaped and prepared for the stacked area chart. It specifies by <code>occupation</code> and <code>sex</code> as the categories (i.e. layers), uses <code>year</code> on the x-axis, and <code>people</code> on the y-axis.</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> dr:<span style="color: #0066CC;">Array</span> = reshape<span style="color: #66cc66;">&#40;</span>ds.<span style="color: #006600;">nodes</span>.<span style="color: #0066CC;">data</span>, <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;occupation&quot;</span>,<span style="color: #ff0000;">&quot;sex&quot;</span><span style="color: #66cc66;">&#93;</span>,
     <span style="color: #ff0000;">&quot;year&quot;</span>, <span style="color: #ff0000;">&quot;people&quot;</span>, _cols<span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Change it to this:</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> dr:<span style="color: #0066CC;">Array</span> = reshape<span style="color: #66cc66;">&#40;</span>ds.<span style="color: #006600;">nodes</span>.<span style="color: #0066CC;">data</span>, <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;category&quot;</span><span style="color: #66cc66;">&#93;</span>,
     <span style="color: #ff0000;">&quot;year&quot;</span>, <span style="color: #ff0000;">&quot;expenditure&quot;</span>, _cols<span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>We only have one category (sans <code>sex</code>), and that's uh, <code>category</code>. The x-axis is still <code>year</code>, and the y-axis is <code>expenditure</code>.</p>
<h3>Step 4. Sorting</h3>
<p><code>Line 84</code> sorts the data by <code>occupation</code> (alphabetically) and then <code>sex</code> (numerically). We'll just sort by <code>category</code>:</p>
<pre class="actionscript"><span style="color: #0066CC;">data</span>.<span style="color: #006600;">nodes</span>.<span style="color: #006600;">sortBy</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;data.category&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Are you starting to get the idea here?</p>
<h3>Step 5. Proper categories</h3>
<p><code>Line 92</code> colors layers by <code>sex</code>, but we don't have that split in our data, so we don't need to do that. Remove the entire row:</p>
<pre class="actionscript"><span style="color: #0066CC;">data</span>.<span style="color: #006600;">nodes</span>.<span style="color: #0066CC;">setProperty</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;fillHue&quot;</span>, iff<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">eq</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;data.sex&quot;</span>,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">0.7</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>We'll come back to customizing the colors of the stacks a little later.</p>
<h3>Step 6. Labeling areas</h3>
<p><code>Line 103</code> adds labels based <code>occupation</code>:</p>
<pre class="actionscript">_vis.<span style="color: #006600;">operators</span>.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> StackedAreaLabeler<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;data.occupation&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>We want to label based on spending <code>category</code>, so we'll change the line accordingly:</p>
<pre class="actionscript">_vis.<span style="color: #006600;">operators</span>.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> StackedAreaLabeler<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;data.category&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<h3>Step 7. Interactive filters</h3>
<p><code>Lines 213-231</code> handle filtering in JobVoyager. First there's the male/female filter and then there's the filter by occupation. We don't need the former, so we can get rid of <code>lines 215-218</code> and then make <code>line 219</code> a plain <code>if</code> statement.</p>
<p>Similarly, <code>lines 264-293</code> at buttons to trigger the male/female filter. We can get rid of that too.</p>
<h3>Step 8. Search categories</h3>
<p>We're getting really close to fully customizing the voyager to our spending data. Go back to the <code>filter()</code> function at <code>line 213</code>. Again, we need to update the function so that we can filter by spending <code>category</code> instead of <code>occupation</code>.</p>
<p>Here's <code>line 222</code> as-is:</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> s:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span>d.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;occupation&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Change <code>occupation</code> to <code>category</code>:</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> s:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span>d.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;category&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<h3>Step 9. Color scheme</h3>
<p>If you ran the code right now, everything should compile correctly, and it'll look something like this:</p>
<p><img src="http://flowingdata.com/wp-content/uploads/2009/12/red-area-545x393.png" alt="red-area" title="red-area" width="545" height="393" class="alignnone size-medium wp-image-4235" /></p>
<p>Color is specified in two places. First <code>lines 86-89</code> specify stroke color and colors everything red:</p>
<pre class="actionscript">shape: Shapes.<span style="color: #006600;">POLYGON</span>,
lineColor: <span style="color: #cc66cc;">0</span>,
fillValue: <span style="color: #cc66cc;">1</span>,
fillSaturation: <span style="color: #cc66cc;">0.5</span>
&nbsp;</pre>
<p>Then <code>line 105</code> updates saturation (the level of red), by count. The code for the <code>SaturationEncoder()</code> is in <code>lines 360-383</code>. We're not going to use saturation though. Instead, we'll explicitly specify the color scheme.</p>
<p>First update <code>lines 86-89</code> to this:</p>
<pre class="actionscript">shape: Shapes.<span style="color: #006600;">POLYGON</span>,
lineColor: 0xFFFFFFFF
&nbsp;</pre>
<p>We're going to make stroke color white with <code>lineColor</code>. If there were more spending categories, we probably wouldn't do this because it'd be cluttered. We don't have that many though, so it'll make reading a little easier.</p>
<p>Next, make an array of the colors we want to use ordered by levels. Put it towards the top around line 50:</p>
<pre class="actionscript"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _reds:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span>0xFFFEF0D9, 0xFFFDD49E, 0xFFFDBB84,
    0xFFFC8D59, 0xFFE34A33, 0xFFB30000<span style="color: #66cc66;">&#93;</span>;
&nbsp;</pre>
<p>I used the <a href="http://colorbrewer2.com">ColorBrewer</a> for these colors.</p>
<p>Then we'll add a new <code>ColorEncoder</code> around <code>line 110</code>:</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> colorPalette:ColorPalette = <span style="color: #000000; font-weight: bold;">new</span> ColorPalette<span style="color: #66cc66;">&#40;</span>_reds<span style="color: #66cc66;">&#41;</span>;
_vis.<span style="color: #006600;">operators</span>.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ColorEncoder<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;data.max&quot;</span>, <span style="color: #ff0000;">&quot;nodes&quot;</span>, <span style="color: #ff0000;">&quot;fillColor&quot;</span>, <span style="color: #000000; font-weight: bold;">null</span>, colorPalette<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Tada, you now have something that looks like what we're after:</p>
<p><img src="http://flowingdata.com/wp-content/uploads/2009/12/orange-area-545x397.png" alt="orange-area" title="orange-area" width="545" height="397" class="alignnone size-medium wp-image-4238" /></p>
<p>Here's the <a href="http://projects.flowingdata.com/america/spending/">finished product</a>.</p>
<h3>Step 10. Download the code and see for yourself</h3>
<p>To play with this yourself, just complete <em>step 0</em> and then replace JobVoyager.as with <a href="http://projects.flowingdata.com/america/spending/JobVoyager.as">this file</a>. It has all the updates we've just covered.</p>
<h3>Step 11. Where to Go From Here</h3>
<p>There's a lot of things you can do with this. You can apply this to your own data, use a different color scheme, and further customize to fit your needs. Maybe change the font or the tooltip format. Then you can get fancier and integrate it with other tools or add more Actionscript, so on and so forth. If anything, you should at least check out what else you can do with Jeffrey's <a href="http://flare.prefuse.org/">Flare visualization toolkit</a>. </p>
<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://flowingdata.com/2009/12/09/how-to-make-an-interactive-area-graph/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>
