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

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Fri 12 May 2006 - 04:47:59 EST

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


      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@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



R-help@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 Received on Fri May 12 04:51:59 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 12 May 2006 - 06:10:10 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.