Take the 2-minute tour ×
Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It's 100% free, no registration required.

I usually make my own idiosyncratic choices when preparing plots. However, I wonder if there are any best practices for generating plots.

Note: Rob's comment to an answer to this question is very relevant here.

share|improve this question

15 Answers 15

up vote 22 down vote accepted

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

share|improve this answer
2  
Tufte's Visual Display of Quantitative Information (amazon.com/o/ASIN/0961392142/ref=nosim/gettgenedone-20) is better than Beautiful Evidence IMO. All four of his books are good though, and if you have an opportunity to attend one of his courses, do it. –  Stephen Turner Jul 21 '10 at 13:57
2  
I agree with most of what Tufte says, but I have to say, his low data:ink boxplots are just plain idiotic. I think they take me 3-4 times longer to figure out than standard boxplots. The R defaults are much better (although the lines on the ends of the tails are unnecessary). Traditional boxplots have the added advantage that they can represent sample size (with width), and standard deviations (with notches). –  naught101 Apr 20 '12 at 1:12
1  
+1 @ naught101 a few others share this opinion over at SO: stackoverflow.com/questions/6973394/… –  Ben Apr 20 '12 at 5:41

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.

share|improve this answer
1  
I agree with the majority of this point, but I think "Keep it simple." could be unclear. Your main point is that you should know what you want the chart to convey. "Keep it simple." brings up some other ideas, like "The data:ink ratio should be high.", which Tufte encourages, and "Present no more than three variables.", which Tufte discourages. –  Thomas Levine Jun 1 '11 at 13:59

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 it's 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.

share|improve this answer
13  
I think you mean sent by fax at some point in the past ;) –  hadley Jul 21 '10 at 12:42
    
+1 for this. Your seminal plot, the heart of your paper, should not be utterly unintelligible because I printed it out. –  Fomite Dec 7 '11 at 14:50
    
this answer addresses a similar problem. –  naught101 Apr 20 '12 at 1:36

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 ration 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.

share|improve this answer

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 advice 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 waisted an hour to explain it.

share|improve this answer

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.
share|improve this answer

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
share|improve this answer
    
Also consider the fact that someone might have to print it out on a greyscale printer. I've done this before - I used ggplot2 default colours (which look great on a screen) for an assignment, which I then printed out in black and white, and half of the colours couldn't be distinguished from the others! *blush* –  naught101 Apr 20 '12 at 1:34

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

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:

  1. Know your message
  2. Know your audience
  3. Know your constraints
  4. 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.

share|improve this answer
    
"Engage", or distract? Colour can be ok, but you're ultimately here about data, and the aesthetics should serve the data, and not the other way around. –  naught101 Apr 20 '12 at 1:31

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)))

enter image description here

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.

share|improve this answer
1  
An example of the trade off for time/space is in the book, Making Maps (critical discussion and examples given here. –  Andy W Apr 20 '12 at 3:41
    
Nice (horrible) example! Maps bring up another, more difficult trade off: trying to represent 2 dimensions+time on a two dimensional page (e.g. maps of continental drift). Pretty difficult. But I guess that's what animations are for :) –  naught101 Apr 20 '12 at 4:05

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.