Re: [R] Question about 'text'

From: Marc Schwartz <MSchwartz_at_mn.rr.com>
Date: Mon 25 Jul 2005 - 04:21:43 EST

On Sun, 2005-07-24 at 18:19 +0100, Dan Bolser wrote:
> On Sun, 24 Jul 2005, John Wilkinson wrote:
>
> >Dan,
> >
> >Another tweak !
> >
> >If you want the 'legend' to look pretty you can resize it by adding,say,
> >
> >'cex=0.6' into the legend code; try---
> >
> >legend("topleft", #inset=-1,
> > legend = do.call("expression", L),
> > bg='white',
> > ncol = 2,
> > pch=c('','','',':',':',':'),
> > x.intersp = 0.4,
> > title="Yay! Thank You!",
> > cex=0.6
> > )
>
> Thats cool, but my biggest problem is using monospaced fonts in a
> postscript output. It dosn't seem to work!
>
> Also, anybody else have the inset= problem?
>
> Cheers for the tweek!
>
> Dan.

Dan,

Try this:

my.slope.1 <-  "   3.22"
my.slope.2 <-  "0.13"
my.inter.1 <-  " -10.66"
my.inter.2 <-  "1.96"
my.Rsqua <-    "   0.97"

# Include Courier font in the PS device
postscript(file = "LM.ps", font = "Courier")

plot(1:5)

L <- list("Intercept",

          "Slope    ",
          bquote(paste(R^2)),
          bquote(.(my.inter.1) %+-% .(my.inter.2)),
          bquote(.(my.slope.1) %+-% .(my.slope.2)),
          bquote(.(my.Rsqua)))


# Set font to Courier for mono spacing
par(family = "Courier")

legend("topleft", inset = .10,

      legend = do.call("expression", L),
      bg = 'white',
      ncol = 2,
      pch = rep(c('', ':'), each = 3),
      x.intersp = 0.1,
      title = "Yay! Thank You!")

dev.off()

Note that the 'inset' argument is to be a fraction of the plot region in the range of 0 - 1. The above setting moves the legend to the right and down from the upper left hand corner by 10% of the plot region width/height.

One more tweak in the legend() call. Use rep() for the pch characters.

HTH, Marc Schwartz



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 Mon Jul 25 04:25:04 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:59 EST