[R] Plotting (mixed) line types and legends
Prof Brian Ripley
ripley at stats.ox.ac.uk
Mon Jul 28 09:26:40 CEST 2003
On 28 Jul 2003, Peter Dunn wrote:
> I have a question about plotting line types and
> legends. Here's a short piece of code to
> x <- y <- seq(1,10)
> plot(x,y, type ="l", lty="33")
> lines(x,y+1, lty=1)
> legend( 8,2,legend=c("lty=1","lty=\"33\""), lty=c(1,"33") )
> On my system (see below), the line types in the legend
> are not the same as in the plot--in particular, lty=1.
> (In the plot, the lty=1 is solid as expected; in the
> legend, it is dots close together.)
> Is this because I shouldn't mix different ways of defining
> line types in the legend? (ie stick to lty=c(1,2) only,
> for example)? If so, I couldn't find it documented.
Yes. You have actually use lty=c("1", "33") by the coercion rules: the
argument you passed has to be one mode and that mode is character.
lty=c("solid", "33") works.
Whether lty="1" should work is a moot point: it seems device-dependent.
It appears to work on postscript() and windows(), so looks like a bug in
the X11() device (which I presume you used, although you did not say so).
On the other hand, one could argue it is a bug that it works anywhere
as it is not as specified in ?par.
> Any explanation appreciated. If anyone know hows to
> do such a thing (ie define different line types in the
> legend), I'd love to hear. (And yes, I need to do it--the
> example above was a short snippet that just demos the problem.)
You have not demonstrated that, and I believe you could always use the
character-string form of lty.
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help