[R] Title and axis

Marc Schwartz MSchwartz at mn.rr.com
Wed Nov 9 14:51:19 CET 2005


On Wed, 2005-11-09 at 10:47 +0200, Mark Miller wrote:
> I was wandering how to set the labels for the axis and how to set the title so 
> that the default title name is not displayed under the title I set. I also 
> use the following to save the plot to a file but it does not seem to save (I 
> use postscript for use in my Latex document)
> 
> x = seq(0,30,0.01)
> postscript("cumIAT.ps")
> plot(ecdf(w1a), do.point=FALSE)
> lines(x, pexp(x,0.405156250))
> title('Cummlative Plot of Monday IATs for entire 15 Weeks')
> dev.off()
> 
> Many thanks
> Mark Miler

Since we cannot fully replicate your code, I'll offer some hints here:

1. For the axis labels and plot title, you can set 'xlab', 'ylab' and
'main' in the plot() call:

plot(ecdf(w1a), do.points = FALSE, 
     xlab = "X Label", ylab = "Y Label",
     main = "Cumulative Plot of Monday IATs\nfor entire 15 Weeks")

Note that I inserted a '\n' (newline) in the title to put it on to two
lines.  If you want it on one line, you will likely need to set
'cex.main' to a number < 1 to reduce the font size.

See ?plot.default for more information.


2. If you are going to use the plot file in LaTeX, you need to create an
Encapsulated Postscript file (EPS), which requires the following
settings:

postscript("cumIAT.eps", horizontal = FALSE, height = 4, width = 4,
           onefile = FALSE, paper = "special")

The critical arguments are 'horizontal', 'onefile' and 'paper'. You can
adjust the 'height' and 'width' arguments as you require.

See the Details section of ?postscript for more information.

The reason that you are not getting a PS file using your code above is
that you are likely getting an error message after the plot() call
indicating that the figure margins are too large. You need to define
larger height and width arguments in the postscript() call to resolve
that issue, as the defaults for your system are not large enough.

BTW, no need to post twice. :-)

HTH,

Marc Schwartz




More information about the R-help mailing list