Tuesday, August 31, 2010

Combining Graph Types

I got a call from my good friend Sandee Cohen (aka vectorbabe) late Friday and our conversation revolved around the topic of graphs in Illustrator. At one point, Sandee had mentioned that she was working with a client who often compared two sets of data using two different graph types -- the result looked as if you had overlayed one graph directly upon another. This can be done in Excel, but Sandee wondered if that could be done in Illustrator as well. My response was "Yes! Illustrator can do that..." and rather than describe to Sandee how it's done, I promised her I'd post it up here on my blog so that everyone else can benefit from it as well...

It's that time of year, and I'm deciding who to draft for my baseball fantasy team. So of course, I've got baseball stats on my mind. And I wondered if it might be interesting to compare the number of home runs a player hits over the course of many seasons to the number of strikeouts that players has had over the same pe! riod of time. It might be interesting to see if there's a trend (for example, as home runs go up, do strikeouts also go up, etc.).

So here are the steps I took to create a chart that compared this data -- using Illustrator's Graph tool.

1. I needed some data on a player, and I picked an easy target -- Barry Bonds. After all, he's been playing for 20 years, has plenty of home runs, and isn't known to strike out very often. It's amazing what you can find on the internet. With the help of Google, not ten seconds passed before I accessed the career stats for Barry -- and I quickly entered the information into an Excel spreadsheet. I should note that using Excel isn't necessary -- I could input data directly into Illustrator, but I added it to Excel for a variety of reasons. First, I'd like to use this data later and it would be nice to have the file handy. Second, most people get data sent to them in Excel format, so this tutorial would be more "complete" ! this way. And third, I wanted to point out something important! about h ow you format data that will be used in Illustrator.

I wanted to list all the years Barry has been playing, which runs from 1986 through 2006. But Illustrator looks at the numbers 1986, 1987, etc. as actual data numbers, not years. If you want a number to be perceived as a value in Illustrator (and not a data point), you must enclose that number in quotation marks, as you can see below.



2. I copied the data from Excel and then switched to Illustrator, and created a new document.

3. I selected the Column Graph tool and dragged out a wide rectangle. This action defined the area for the graph and brought up the Graph Data window. I then chose Edit > Paste to bring the data from Excel into my graph's data window, which looked like this:



Again, it's important to emphasize that I had to place quotation mar! ks around the years, or Illustrator would have charted those numbers as data points.

4. I applied the data to my graph by clicking on the checkmark icon in the Graph Data window (upper right corner). I then closed the Graph Data window. My resulting graph appeared as so:



I know, the graph doesn't look very charming, and because there are so many years, the labels across the bottom of the graph are all overlapping each other. Don't worry -- we'll make everything look fabulous soon enough. Which by the way, is one of the reasons why it's NEVER a good idea to have a client sit with you while you work (I can just hear them saying "but I don't WANT the chart to be colored gray...").

5. OK, so the first order of business is to use a different type of chart to show the different sets of data. I like the column format for the number of strikeouts, but it would be totally cool if I could di! splay the home runs as a line graph, so it would be easier to ! track th em. Using the Group Selection tool, I clicked TWICE on the rectangle next to the word Home Runs in the LEGEND of the chart.

6. At this point, all of the values for the Home Runs in my chart are selected. I then double-clicked on the Graph tool in the Tools palette (toolbar, toolbox, whatever you call it). This action brings up the Graph Type dialog box.

7. Since I wanted to display the Home Runs as a line, I selected the Line option in the Graph Type dialog, and clicked OK. The chart now updated to display the Home Runs as a line graph, while keeping the Strikouts as a column graph. The result looked like this:



8. Now that the data and the graph types were complete, I was able to make the graph look "pretty". I used colors to differentiate the years that Barry was on the Pirates (yellow bars) and on the Giants (orange bars), I adjusted the type to look nice, changed the color of the! line, and added a drop shadow to the line as well. The final graph looked like this:



Looking at the final chart, one can quickly see that as of 1999, Barry has had significantly fewer strikeouts compared to his hitting more home runs. I would argue that the number of walks have also increased during those years, which would have an effect on that, and maybe adding walks to the graph would help visualize that as well -- consider that homework for my dedicated readers...

So there you have it -- a single chart with different graph types displaying different data points. If you need to edit the data, you can simply edit that one chart, and everything will update nicely. Even the formatting will remain intact, as the final graph was never ungrouped.

Thanks for the request Sandee!

Types of Graph

No comments:

Post a Comment