[R] Question about 'text'

Marc Schwartz MSchwartz at mn.rr.com
Sun Jul 24 20:21:43 CEST 2005


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




More information about the R-help mailing list