Re: [R] Labelling curves on graphs

From: Barry Rowlingson <>
Date: Thu, 17 Jul 2008 08:47:16 +0100

> Why use color when you can use black and label the curves where they are
> most separated?  This solves problems with color blindness, xeroxing, and
> faxing.

Where should I put the labels in this example:

> set.seed(123)
> z=matrix(runif(6*50),50,6)
> matplot(z,type='l',col=1,lty=1)

A label is only going to indicate which curve is which at a point. If the curves approach or cross anywhere you're going to get confused. Line styles and colours persist along the length of the line.

For nice smooth well-behaved curves then perhaps labelling is okay - contour lines rarely cross, and even when they do they must have the same height value anyway.

I'm not sure once you get to six lines on a graph you can find six distinctive line styles without using colour, so it might be better to switch graphic completely. Compare the above plot with image(z).

If the plots don't cross, one solution is to extend the plot to the right and just add labels there:

> set.seed(123)
> z=matrix(runif(6*50),50,6)
> m=apply(z,1,cumsum)
> ms=apply(m,1,sort)
> matplot(ms,type='l',xlim=c(0,55),lty=1,col=1)
> text(50,ms[50,],c("Foo","Bar","Baz","Qux","Quux","Quuux"),adj=-0.1)

I can't see a neater way of putting labels actually on the lines in this case - they'll be all over the place to squeeze them in the gaps.


        [[alternative HTML version deleted]] mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Thu 17 Jul 2008 - 07:56:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 Jul 2008 - 12:31:58 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive