[R] legend in R plot

Carl Witthoft carl at witthoft.com
Fri Jul 23 00:10:48 CEST 2010


It occurs to me that Hannah may simply be plotting to a plot window that 
is overall too small.
Try setting the plot window to full-screen (or close to that), and then 
running your plot & legend.   Once the picture on the screen is the way 
you like it,  save or copy (clipboard) to your format of choice, and 
then resize the plot image with some other tool.  The line segments in 
the legend box should scale nicely.

Carl


-----
From: Peter Ehlers <ehlers_at_ucalgary.ca>
Date: Thu, 22 Jul 2010 02:36:32 -0600

On 2010-07-21 22:06, li li wrote:
 > Hi all,
 > I am have some difficulty with the legend function.
 > I need to add a legend to describe the different line types in a 
plot. The
 > legend box is small.
 > It did not include sufficient length of each line type to help 
distinguish
 > the differnt line types.
 > Is there a way to fix this.
 > Thank you
 > Hannah
 >

If I understand correctly, you want to have longer line segments in your 
legend. I agree that this is sometimes desirable but, with the current 
code, it's not possible - the segment length is hard-coded.

If it matters enough to you, you can easily modify the code to achieve 
your aim: search for the following two lines and in each replace the '2' 
with a greater value, say '3'.

First line:

              w0 <- w0 + (2 + x.off) * xchar

Second line:

          seg.len <- 2

I don't think that this will have any undesirable side effects, but I 
haven't given it much thought. I haven't had any problems with this 
version of legend().

    -Peter Ehlers



More information about the R-help mailing list