# Color and line thickness recommendations for line plots

Much has been written about color blind-friendly color choices for maps, polygons, and shaded regions in general (see for example http://colorbrewer2.org). I have not been able to find recommendations for line colors and varying line thickness for line graphs. Goals are:

1. easily distinguish lines even when they intertwine
2. lines are easy to distinguish by individuals with the most common forms of color blindness
3. (less important) lines are printer-friendly (see Color Brewer above)

In the context of black and gray scale lines I have found it very effective to have thin black lines and thicker gray scale lines. I would appreciate specific recommendations that include varying colors, degree of gray scale, and line thickness. I am not as fond of varying line types (solid/dotted/dashed) but could be talked out of that opinion.

It would be preferable to have recommendations for up to 10 curves on one graph. Even better would be to do as Color Brewer does: allow recommendations for m lines to not be a subset of recommendations for n lines where n > m, and to vary m from 1 to 10.

Please note: I would also appreciate guidance that addresses only the line coloring part of the question.

Some practitioners add symbols to lines every few centimeters to better distinguish different classes. I'm not so much in favor that requires more than one feature (e.g., color + symbol type) to distinguish the classes, and would sometimes like to reserve symbols to denote different information.

In the absence of other guidance, I propose to use the same colors recommended for polygons in colorbrewer2.org for lines, and to multiply the line width by 2.5 for lines drawn with less bright/dense colors. I'm creating an R function that sets this up. In addition to the color brewer colors I think I'll make the first 2 colors be solid black (thin) and gray scale (thick) although one could argue that they should be thin solid black and thin blue.

R functions may be found at http://biostat.mc.vanderbilt.edu/wiki/pub/Main/RConfiguration/Rprofile . Once you define the function colBrew you can see how the settings work by typing

showcolBrew(number of line types)  # add grayscale=TRUE to use only grayscale


A function latticeSet is also given, for setting lattice graphics parameters to the new settings. Improvements to the algorithms are welcomed.

To explore: R dichromat package: http://cran.r-project.org/web/packages/dichromat/

• I would have thought that a limited number of line types would be very helpful. Another option that doesn't seem to have been mentioned yet, is the use of point markers for individual measurements, e.g, crosses, zeroes, asterisks, etc. – Robert Jones Dec 3 '14 at 21:25
• To me, point markers are not fully effective when curves intertwine. But I've seen several examples where they work very well. – Frank Harrell Dec 3 '14 at 22:17

I will try to be provocative here and wonder whether the absence of such guidelines arises because this is a nearly insoluble problem. People in quite different fields seem to agree in often talking about "spaghetti plots" and the problems they pose in distinguishing different series.

Concretely, a mass of lines for several individual time series can collectively convey general patterns and sometimes individual series that vary from any such pattern.

The question, however, I take to be about distinguishing all the individual time series when they have identities you care about.

If you have say 2 or 3 series, distinguishing series is usually not too difficult, and I would tend to use solid lines in two or three of red, blue or black. I've also played with orange and blue as used by Hastie and friends (see answer from @user31264).

Varying the line pattern (solid, dash, dotted, etc.) I have found of only limited value. Dotted lines tend to be washed out physically and mentally and the more subtle combinations of dots and dashes are just too subtle (meaning, slight) in contrast to be successful in practice.

I'd say the problem bites long before you have 10 series. Unless they are very different, 5 or so series can be too much like hard work to distinguish. Common psychology seems to be that people understand the principle that different series are indicated by different colours and or symbolism perfectly well, but lack the inclination to work hard at tracing the individual lines and trying to hold a story about their similarities and differences in their heads. Part of this often stems from the use of a legend (or key). It's controversial, but I'd try to label different series on the graph wherever possible. My motto here is "Lose the legend, or kill the key, if you can".

I've become fonder of a different approach to showing multiple time series, in which all the different time series are shown repeatedly in several panels, but a different one is highlighted in each one. That's a fusion of one old idea (a) small multiples (as Edward Tufte calls them) and another old idea (b) highlighting a series of particular interest. In turn it may just be yet another old idea rediscovered, but so far I can only find recent references. More in this thread on Statalist.

In terms of colours, I am positive about using greys for time series that are backdrop to whatever is being emphasised. That seems to be consistent with most journals worth publishing in.

Here is one experiment. The data are grain yields from 17 plots on the Broadbalk Fields at Rothamsted 1852-1925 and come from Andrews, D.F. and Herzberg, A.M. (Eds) 1985. Data: A collection of problems from many fields for the student and research worker. New York: Springer, Table 5.1 and downloadable from various places (e.g. enter link description here. (Detail: The data there come in blocks of 4 lines for each year; the third and fourth lines are for straw yield, not plotted here. The plot identifiers are not explicit in that table.)

I have no specific expertise on this kind of data; I just wanted a multiple time series that couldn't (easily) be dismissed as trivially small in terms of length of series or number of panels. (If you have hundreds, thousands, ... of panels, this approach can't really help much.) What I am imagining is that a data analyst, perhaps talking to a subject-matter expert, could identify a variety of common and uncommon behaviours here and get insights and information thereby.

Evidently this recipe could be used for many other kinds of plots (e.g. scatter plots or histograms with each subset highlighted in turn); together with ordering panels according to some interesting or useful measure or criterion (e.g. by median or 90th percentile or SD); and for model results as well as raw data.

• I'm very impressed by subsetplot. Could you include some sample output images directly into your post? I'm curious how well it works as the number of lines vary, but this is definitely the most satisfying solution I've seen for ~10 lines – Silverfish Dec 5 '14 at 16:44
• @Silverfish Thanks for the encouragement. One experiment now added. – Nick Cox Dec 5 '14 at 18:51
• Nick I am fully in agreement with "lose the label" - minimizing remote legends - and with the use of highlighting one curve at a time, letting others dim as you did [you can be almost as effective using solid black for the highlighted curve]. I think this is a great idea for presentations but is not so optimal for publishing a paper because of space limitations. – Frank Harrell Dec 5 '14 at 20:14
• Maybe interact plots will soon become more of a standard in publishing and we will be able to hover over lines in plots and gain more information (have the whole line be highlighted or show a tooltip to give you more info etc). – bdeonovic Dec 5 '14 at 20:32
• @Frank Harrell The question of space bites (1) if individual graph panels become too small to be readable, in which case the merits of the design are dubious; (2) if journals or book editors can't be persuaded to assign more space for a larger figure than normal if it seems worthwhile. (Perhaps you had other points in mind.) – Nick Cox Dec 6 '14 at 10:19

Questions 2 and 3 you answered yourself - the color brewer palettes are suitable. The hard question is 1, but like Nick I'm afraid it is based on a false hope. The color of the lines are not what makes one be able to distinguish between the lines easily, it is based on continuity and how tortuous the lines are. Thus there are design based choices, other than the color or dash pattern of the lines, that will aid in making the plot easier to interpret.

I will steal one of Frank's diagrams showing the flexibility of splines to approximate many different shaped functions over a limited domain as an example.

#code adapted from http://biostat.mc.vanderbilt.edu/wiki/pub/Main/RmS/rms.pdf page 40
library(Hmisc)
x <- rcspline.eval(seq(0,1,.01), knots=seq(.05,.95,length=5), inclx=T)
xm <- x
xm[xm > .0106] <- NA
x <- seq(0,1,length=300)
nk <- 6
set.seed(15)
knots<-seq(.05,.95,length=nk)
xx<-rcspline.eval(x,knots=knots,inclx=T)
for(i in 1:(nk−1)){
xx[,i]<-(xx[,i]−min(xx[,i]))/
(max(xx[,i])−min(xx[,i]))
for(i in 1:20){
beta<-2∗runif(nk−1)−1
xbeta<-xx%∗%beta+2∗runif(1)−1
xbeta<-(xbeta−min(xbeta))/
(max(xbeta)−min(xbeta))
if (i==1){
id <- i
MyData <- data.frame(cbind(x,xbeta,id))
}
else {
id <- i
MyData <- rbind(MyData,cbind(x,xbeta,id))
}
}
}
MyData$id <- as.factor(MyData$id)


Now this produces quite a tangled mess of 20 lines, a difficult challenge to visualize.

library(ggplot2)
p1 <- ggplot(data = MyData, aes(x = x, y = V2, group = id)) + geom_line()
p1


Here is the same plot in small multiples, at the same size, using wrapped panels. It is slightly more difficult to make comparisons across panels, but even in the shrunken space it is much easier to visualize the shape of the lines.

p2 <- p1 + facet_wrap(~id) + scale_x_continuous(breaks=c(0.2,0.5,0.8))
p2


One point that Stephen Kosslyn makes in his books is that it isn't how many different lines make the plot complicated, it is how many different types of shapes the lines can take. If 20 panels end up being too small, you can frequently reduce the set to similar trajectories to place in the same panel. It is still hard to distinguish between the lines within the panels, by definition they will be nearby each over and overlap frequently, but it reduces the complexity of making between panel comparisons quite a bit. Here I arbitrarily reduced the 20 lines into 4 separate groupings. This has the added benefit that direct labelling of lines is simpler, there is more space within the panels.

###############1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
newLevels <- c(1,1,2,2,2,2,2,1,1, 2, 3, 3, 3, 3, 2, 4, 1, 1, 2, 1)
MyData$idGroup <- factor(newLevels[MyData$id])
p3 <- ggplot(data = MyData, aes(x = x, y = V2, group = id)) + geom_line() +
facet_wrap(~idGroup)
p3


There is a general phrase that is applicable to the situation, if you focus on everything you focus on nothing. In the case with only ten lines, you have (10*9)/2=45 possible pairs of lines to compare. We probably are not interested in all 45 comparisons in most circumstances, we are either interested in comparing specific lines to each other or comparing one line to the distribution of the rest. Nick's answer shows the latter nicely. Drawing the background lines thin, light colored, and semi-transparent, and then drawing the foreground line in any bright color and thicker will be sufficient. (Also for the device make sure to draw the foreground line on top of the other lines!)

It is much more difficult to create a layering where each individual line can be easily distinguished in the tangle. One way to accomplish foreground-background differentiation in cartography is the use of shadows, (see this paper by Dan Carr for a good example). This will not scale up to 10 lines, but can help for 2 or 3 lines. Here is an example for the trajectories in Panel 1 using Excel!

There are other points to make, such as the light grey lines can be misleading if you have trajectories that are not smooth. E.g. you could have two trajectories in the shape of an X, or two in the shape of one right side up and upside down V. Drawing them the same color you wouldn't be able to trace the lines, and this is why some suggest drawing parallel coordinate plots using smooth lines or jittering/off-setting the points (Graham and Kennedy, 2003; Dang et al., 2010).

So the design advice can change depending on the end goal and the nature of the data. But when making bivariate comparisons between the trajectories is of interest, I think the clustering of similar trajectories and using small multiples makes the plots much easier to interpret in a wide variety of circumstances. This I feel is generally more productive than any combination of colors/line dashes will be in complicated plots. Singled panel plots in many articles are much larger than they need to be, and splitting into 4 panels is typically possible within page constraints without much loss.

• Andy this is wonderful. I do think that for this particular spline curve example it would be just as effective, or even more effective, to assign 5 colors to the 20 lines so that curves that are closer together are assigned different colors. There is no one distance metric that will always work but there is usually a metric that works for a given situation. As you said all this depends on smoothness and tortuousity. – Frank Harrell Dec 7 '14 at 15:55

From "The Elements of Statistical Learning" by Trevor Hastie et al. :

"Our first edition was unfriendly to colorblind readers; in particular, we tended to favor red/green contrasts which are particularly troublesome. We have changed the color palette in this edition to a large extent, replacing the above with an orange/blue contrast."

You may want to look at their graphs.

You may also use dashed, dotted etc. lines.

I've seen very little attention given to "line thickness" in regards to proper data visualization. Perhaps the ability to discern different line thicknesses is not as variable as the ability to discern color.

Some resources:

1. Hadley Wickham ( 2009), ggplot: Elegant Graphics for Data Analysis, Springer; has a supporting web page

Some courses:

1. Graphics Lecture in Thomas Lumley's Introductory computing for biostatistics course
2. Ross Ihaka's graduate course on computational data analysis and graphics
3. Ross Ihaka's undergraduate course on information visualization
4. Deborah Nolan's undergraduate course Concepts in Computing with Data
5. Hadley Wickham's Data visualization course
• That's a great list of resources. However, are there any specific recommendations you're aware of - from one or more of them - that relate to the question (line thickness, with colored lines, where there may be many lines), which you could briefly mention? – Glen_b Dec 3 '14 at 20:05
• I took the liberty of formatting your post. I think it makes it easier to see the structure. If you don't like it, roll it back with my apologies. – gung - Reinstate Monica Dec 5 '14 at 20:27

While I agree that there's not a unique solution to the problem, I use the recommendation of this blog:

http://blogs.nature.com/methagora/2013/07/data-visualization-points-of-view.html

The posts on colour tackle the issues of colour-blindness and Gray-scale printing and gives an example of colour scale that solves this both issues.

In the same articles is analysed also the continuous colour scales, which many uses for heat plots and so on. It is recommended not to use the rainbow, because of some sharp transitions (like the yellow zone, much smaller than the red). Instead, it is possible to make transitions between other pairs of colours.

A good set of colours for this purpose is blue and orange (a classic!). You can make a test, by applying colour-blind and Gray filters and see if you can still notice the difference.

For the thickness of lines, some of the issues of the blog mentioned before deal with this point. Lines, if you have many, should have the same thickness, that is "thin". Use thick lines only if you want to call attention to that object.

• I don't fully agree with the "Use thick lines only ...". Thick light gray-scale lines can be very effective in many cases. – Frank Harrell Jan 23 '16 at 14:02
• It can be surely. I just meant that if you use an eye-catching style, it should be used with a purpose. – chuse Jan 25 '16 at 17:58