[R] Legend titles in log plots broken? (ver. 2.2.1)

Duncan Murdoch murdoch at stats.uwo.ca
Thu May 11 20:47:59 CEST 2006


I forgot to mention:  if you want to use the patch without installing a 
new version of R, it's available by sourcing the file

https://svn.r-project.org/R/branches/R-2-3-patches/src/library/graphics/R/legend.R

It was just a one character change:

Index: legend.R
===================================================================
--- legend.R    (revision 38022)
+++ legend.R    (revision 38033)
@@ -226,7 +226,7 @@

      xt <- xt + x.intersp * xchar
      if(plot) {
-       if (!is.null(title)) text(left + w/2, top - ymax, labels = title,
+       if (!is.null(title)) text2(left + w/2, top - ymax, labels = title,
                                   adj = c(0.5, 0), cex = cex, col = 
text.col)

         text2(xt, yt, labels = legend, adj = adj, cex = cex, col = 
text.col)


Duncan Murdoch

Rob Steele wrote:
> Legend titles work in linear plots:
> 
> curve(1/x, xlim = c(0, 1))
> legend(x = 'topright', inset = 0.04,
>         legend = '1/x', lty = 1,
>         title = 'Legend Title')
> 
> But when you change to a log plot on either dimension things get screwy:
> 
> curve(1/x, xlim = c(0, 1), log = 'y')
> legend(x = 'topright', inset = 0.04,
>         legend = '1/x', lty = 1,
>         title = 'Legend Title')
> 
> If you save the value legend() returns you can look at it and see that 
> it's messed up:
> 
> l <- legend(x = 'topright', inset = 0.04,
>              legend = '1/x', lty = 1,
>              title = 'Legend Title')
> 
>  > l
> $rect
> $rect$w
> [1] 0.2349272
> 
> $rect$h
> [1] 0.2727899
> 
> $rect$left
> [1] 0.7618728
> 
> $rect$top
> [1] 1.9936
> 
> 
> $text
> $text$x
> [1] 0.9188374
> 
> $text$y
> [1] 1.81174
> 
> 
>  > R.Version()
> $platform
> [1] "i686-redhat-linux-gnu"
> 
> $arch
> [1] "i686"
> 
> $os
> [1] "linux-gnu"
> 
> $system
> [1] "i686, linux-gnu"
> 
> $status
> [1] ""
> 
> $major
> [1] "2"
> 
> $minor
> [1] "2.1"
> 
> $year
> [1] "2005"
> 
> $month
> [1] "12"
> 
> $day
> [1] "20"
> 
> $"svn rev"
> [1] "36812"
> 
> $language
> [1] "R"
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list