[R] legend(): adjust space between symbol and text : x.intersp=.

Martin Maechler maechler at stat.math.ethz.ch
Tue Sep 14 10:26:09 CEST 1999


>>>>> On Sat, 11 Sep 1999 15:05:25 +0200, Knut Suebert <ksueber at gwdg.de> said:

    Knut> I'd like to ask, how to adjust the space between symbol/line and
    Knut> text in a legend. My legend() is build like that

  legend(xmax-netzdiff/11,                  # shouldn't matter here
         ifelse(ydiff>=0,                   #
	        ymin-6.5*(netzdiff/11),     #
	        ymax-netzdiff/11),          #
	 c("stehender Stamm","Windwurf",
	   "Eklektor","Thermometer","Kreuzfalle"),
         col=c("#000000","#808080","#707070","#A0A0A0","#404040"),
	 merge=T, 
	 pch=c( 1,-1, 5,20, 4),
	 lty=c(-1, 1,-1,-1,-1),
	 xjust=1, yjust=ifelse(ydiff>=0,-1,1),
	 y.intersp=0.8, cex=0.6)
		
    Knut> and looks like http://www.gwdg.de/~ksueber/beispiel.jpg or

    Knut> +-------------------------+
    Knut> |O        stehender Stamm |
    Knut> |--       Windwurf        |
    Knut> |#        Eklektor        |
  
    Knut> and so, but it should look something like

    Knut> +----------------------+
    Knut> |  O   stehender Stamm |
    Knut> | ---  Windwurf        |
    Knut> |  #   Eklektor        |

    Knut> and so on. Most important for me would be to reduce the space between
    Knut> symbols and text. 

Use  x.intersp = 1.5  (or so).
     -----------
Here is your example, extended and reproducible

##--------------------
leg1 <- c("stehender Stamm", "Windwurf","Eklektor", "Thermometer", "Kreuzfalle")
col1 <- c("#000000","#808080","#707070","#A0A0A0","#404040")
pch1 <- c( 1,-1, 5,20, 4)
lty1 <- c(-1, 1,-1,-1,-1)

plot(1)
legend(1,1, legend= leg1, col= col1, merge=TRUE, pch=pch1, lty=lty1, trace=TRUE)
## to see defaults				                     ==========
## Defaults: x.intersp = 3 ; y.intersp = 1.2
legend(1,1.1, legend= leg1, col= col1, merge=TRUE, pch=pch1, lty=lty1,
       y.intersp = .8, cex = 0.6, bg = "lightskyblue")
legend(1.03,1.22, legend= leg1, col= col1, merge=TRUE, pch=pch1, lty=lty1,
       x.intersp = 1.5, y.intersp = .9, cex = 0.6, bg='light green')
legend(1,0.75, legend= leg1, col= col1, merge=TRUE, pch=pch1, lty=lty1,
       x.intersp = 1.5, y.intersp = 1, cex = 0.4, bg='light steel blue')
##--------------------


Note that legend() had been enhanced (from its origin) by
Ben Bolker (and me) in order to provide the current functionality.
One main issue was
    1) reasonable defaults for many situations
    2) configurable by the user.
The computation of the box (drawn around the legend) dimensions
tries to be smart, using  strwidth() and strlength() and some heuristics
(dependency on "cex" argument) which might still be quite a bit improvable.

Deficiencies come from at least
	     - strwidth(ch) & strlength(ch) currently depend on the font,	
	       rather than the characters *used* in ch.
	     - Fonts exist in discrete sizes only, whereas as 'cex' is 
	       continuous.

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO D10	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list