I usually make my own idiosyncratic choices when preparing plots. However, I wonder if there are any best practices for generating plots.
The Tufte principles are very good practices when preparing plots. See also his book Beautiful Evidence
The principles include:
- Keep a high data-ink ratio
- Remove chart junk
- Give graphical element multiple functions
- Keep in mind the data density
The term to search for is Information Visualization
We could stay here all day denoting best practices, but you should start by reading Tufte. My primary recommendation:
Keep it simple.
Often people try to load up their charts with information. But you should really just have one main idea that you're trying to convey and if someone doesn't get your message almost immediately, then you should rethink how you have presented it. So don't start working on your chart until the message itself is clear. Occam's razor applies here too.
One rule of thumb that I don't always follow but which is on occasion useful is to take into account that it is likely that your plot will at some point in its future be
- sent by fax,
- photocopied, and/or
- reproduced in black-and-white.
You need to try and make your plots clear enough that even if they are imprecisely reproduced in the future, the information the plot is trying to convey is still legible.
In addition to conveying a clear message I always try to remember the plotsmanship:
- font sizes for labels and legends should be big enough, preferably the same font size and font used in the final publication.
- linewidths should be big enough (1 pt lines tend to disappear if plots are shrunk only slightly). I try to go to linewidths of 3 to 5 pt.
- if plotting multiple datasets/curves with color make sure that they can be understood if printed in black-and-white, e.g. by using different symbols or linestyles in addition to color.
- always use a lossless (or close to lossless) format, e.g. a vector format like pdf, ps or svg or high resolution png or gif (jpeg doesn't work at all and was never designed for line art).
- prepare graphics in the final aspect ratio to be used in the publication. Changing the aspect ratio later can give irritating font or symbol shapes.
- always remove useless clutter from the plotting program like unused histogram information, trend lines (hardly useful) or default titles.
I have configured my plotting software (matplotlib, ROOT or root2matplotlib) to do most of this right by default. Before I was using
gnuplot which needed extra care here.
In the physics field there is a rule that the whole paper/report should be understandable only from quick look at the plots. So I would mainly advise that they should be self-explanatory.
This also implies that you must always check whether your audience is familiar with some kind of plot -- I had once made a big mistake assuming that every scientist knows what boxplots are, and then wasted an hour to explain it.
Here are my guidelines, based on the most common errors I see (in addition to all the other good points mentioned)
- Use scatter graphs, not line plots, if element order is not relevant.
- When preparing plots that are meant to be compared, use the same scale factor for all of them.
- Even better - find a way to combine the data in a single graph (eg: boxplots are a better than several histograms to compare a large number of distributions).
- Do not forget to specify units
- Use a legend only if you must - it's generally clearer to label curves directly.
- If you must use a legend, move it inside the plot, in a blank area.
- For line graphs, aim for an aspect ratio which yields lines that are roughly at 45o with the page.
Take a look at the R graphics library, ggplot2. Details are at the web page http://had.co.nz/ggplot2/ This package generates very good default plots, that follow the Tufte principles, Cleveland's guidelines and Ihaka's color package.
If plotting in color, consider that colorblind people may have trouble distinguishing elements by color alone. So:
- Use line styles to distinguish lines.
- Use extra weight in elements, make linewidth at least 2 pt, etc.
- Use different markers as well as colors to distinguish points.
- Use labels and annotations, referring to position and style also.
- When referring to plot elements in text, describe them by color, relative position and style: "the red, upper, dash-dot curve"
- Use a colorblind friendly palette. See http://www.vischeck.com/vischeck/, , http://jfly.iam.u-tokyo.ac.jp/color/#pallet. I have a simple python implementation of the palette in the last reference at code.google.com, look for python-cudtools
These are wonderful suggestions. We have assembled a lot of material at http://biostat.mc.vanderbilt.edu/StatGraphCourse. A group of statisticians in the pharma industry, academia, and FDA are also creating a resource that will be very useful for clinical trials and related research. Much new material will be unveiled in a month but a lot is already there - http://www.ctspedia.org/do/view/CTSpedia/PageOneStatGraph
My personal favorite graphics book is Elements of Graphing Data by William Cleveland.
In terms of software, in my opinion it is hard to beat R's ggplot2 and lattice packages. Stata also supports some excellent graphics.
It also depends on where you wan't to publish your plots. You'll save yourself a lot of trouble by consulting the guide for authors before making any plots for a journal.
Also save the plots in a format that is easy to modify or save the code you have used to create them. Chances are that you need to make corrections.
Don't use dynamite plots: http://pablomarin-garcia.blogspot.com/2010/02/why-dynamite-plots-are-bad.html, use violin plots or similar (boxplots family)
The other answers are too formulaic to be convincing, so let me give a more general answer. I've struggled with this question for a while. I offer this process:
- Know your message
- Know your audience
- Know your constraints
- Tailor your message to your audience given your constraints
I am skeptical of blanket claims such as "keep it simple" -- what does that mean? Well, it depends on the audience. Some audiences will eat up the Tufte style. But some audiences appreciate a little chart junk now and then. Some people are bored by scatterplots. Some people like colorful backgrounds. Is it so wrong to engage them a little bit even if you compromise "aesthetic" purity? That is up to you to decide.
Your audience's reaction will be an important piece of feedback, but not the only one. If you find a way to measure their understanding before and after your presentation, then you will start to understand the impact you've made.
The "right" answer will depend upon these sorts of questions:
What media will you be using?
Are you creating static or interactive plots?
Are you trying to tell a pre-defined story (exposition) or encourage experimentation (exploration)?
To what degree do you want the audience to draw their own conclusions?
To what degree to you want the audience to follow along with and be convinced by your story?
To what degree to you want the audience to challenge your findings?
In summary, design your materials deliberately given your message, audience, and constraints.
One thing that I seem to remember Tufte mentioning, that isn't in the other answers is mapping - that is, make position, direction, size, etc. on your graph represent reality. What is up on the graph should be up in the real world. What is big should be big (keeping in mind that areas should represent areas, and volumes volumes. Never try to represent a scalar value by an area, it's highly ambiguous!). This also applies to colours, shapes, etc, if they are relevant.
An interesting example is the "skirt series" graph here: http://a-little-book-of-r-for-time-series.readthedocs.org/en/latest/src/timeseries.html. While technically it's correct, and a "taller" skirt length occupies a higher position on the graph, it's actually quite confusing, because skirt length starts from the top, and goes down (unlike humans, or trees, where we measure the height from the ground). So increased skirt length actually represents a lower value:
skirts <- scan("http://robjhyndman.com/tsdldata/roberts/skirts.dat",skip=5) skirtsseries <- ts(skirts,start=c(1866)) plot.ts(skirtsseries, ylim=c(max(skirts),min(skirts)))
There are, as always, difficulties. For example, we generally consider time to move forward, and in the west, at least, we read left to right, so our time-series graphs also usually flow left to right as time increases. So what happens if you want to represent something that's best represented laterally (e.g. east-west measurements of something), over time? In that case, you have to compromise, and either portray time a moving up or down (which one depends again on cultural perceptions, I guess), or choose to map your lateral variable to up/down on your graph.
It depends on the way in which the plots will be discussed.
For instance, if I'm sending out plots for a group meeting that will be done with callers from different locations, I prefer putting them together in Powerpoint as opposed to Excel, so it's easier to flip around.
For one-on-one technical calls, I'll put something in excel so that the client be able to move a plot aside, and view the raw data. Or, I can enter p-values into cells along side regression coefficients, e.g.
Keep in mind: plots are cheap, especially for a slide show, or for emailing to a group. I'd rather make 10 clear plots that we can flip through than 5 plots where I try to put distinct cohorts (e.g. "males and females") on the same graph.
I would add that the choice of plot should reflect the type of statistical test used to analyse the data. In other words, whatever characteristics of the data were used for analysis should be shown visually - so you would show means and standard errors if you used a t-test but boxplots if you used a Mann-Whitney test.