Skip to content

axis() default values for "lty", "lwd", and "col"

4 messages · Jerome Asselin, Brian Ripley, Martin Maechler

#
Hi,

I would like to recommend a minor modification in axis() which I believe 
can simplify the making of plots for publications. I am trying to define 
default values for par() in order to make labels bigger and lines thicker, 
so that the resulting plots look good when resized for publication 
purposes. I ran into the following problem...

axis() does not use par() values as default for "lty", "lwd", and "col". 
Here is an example.

par(lty=2,lwd=3,col="blue")
plot(1,1,bty="n",axes=F)
axis(1)
axis(2)

Because axis() doesn't use the par() values, I have to explicitely define 
the parameters "lty", "lwd", and "col" in my axis() calls. It would make 
sense if axis() used the par() values by default.

Hence, I recommend this simple fix in the axis() function([...]) statement 
in order to have axis() read the par() values for "lty", "lwd", and "col".

axis <- 
function (side, at = NULL, labels = TRUE, tick = TRUE, line = NA,
    pos = NA, outer = FALSE, font = NA, vfont = NULL, lty = par("lty"),
    lwd = par("lwd"), col = par("col"), ...)
{ [...] }

I use R1.7.0 on Red Hat Linux 7.2.

Sincerely,
Jerome Asselin
#
I believe this to be deliberate.  If I do

par(lty=2,lwd=3,col="blue")
plot(1:10)

I do not want the axes to be thick, dotted and blue, with black labels.
(It is also I suspect deliberate that

plot(1:10,lty=2,lwd=3,col="blue")

does not pass any of those parameters on to axis().)

You say you made the labels bigger: to do that you needed to set cex.axis 
and cex.main, not cex.

I'm afraid this change would break a lot of existing code.  I am aware 
that S-PLUS does this (with blue labels too), and I have always found it
irritating to have to work around it.
On Tue, 20 May 2003, Jerome Asselin wrote:

            

  
    
#
Thank you Prof Ripley for your comments. Let me explain in greater detail 
what I was thinking.

I agree that blue dotted axes are quite unusual, but thicker axes are 
useful. With the default lwd=1, some tickmarks don't show up if I shrink 
my plot and then print it on paper. Using lwd=2 for axes does fix that 
problem, but I have to make separate calls to axis() with option lwd=2 in 
order to do that.

My vision was that par() would give default values for everything 
(including lwd, lty and col) to be plotted in the graphical device. The 
user would explicitely define parameters in specific functions when 
different options are required.

For example, the following would give axes and tickmarks of lwd=2, but the 
diagonal line would be of lwd=4.
par(lwd=2)
plot(1:10,type="l",lwd=4)
Note that the box around the plot is of lwd=2 (as I would expect), but the 
axes (which are hidden under the box) and tickmarks are drawn with lwd=1. 
So there is an inconsistency between the width of the box and the 
tickmarks (and "hidden" axes). Why should there be?

Moreover, I think the user should have a good reason for using
  par(lty=2,lwd=3,col="blue")
  plot(1:10)
as opposed to
  dev.off() #clean up!
  plot(1:10,lty=2,lwd=3,col="blue")
These two ways of plotting are very different. In the first way, the 
parameters lty=2, lwd=3, and col="blue" should apply to everything in the 
graphical window, whereas in the second way they should apply only to the 
points.

Ideally, the distinction should be clear and consistent for all plotting 
functions. I also share your concerns that "this change would break a lot 
of existing code".

Sincerely,
Jerome Asselin
On May 20, 2003 11:28 pm, Prof Brian Ripley wrote:
#
Jerome,

I understand your wish, but as Prof Ripley said, 
we have very good reasons to not got that way.
For your situation, please use global  par() settings.

But for the general problem, I'm musing on a bit... :

1.  One should use  library(grid) {plus sometimes (lattice)}
    instead, but given the current non-compatibility with
    base graphics, this won't always work.

2.
  R has more  par() options than AT&T S or S-plus -- exactly for
  the purpose of setting col/cex/... setting for axis labels separately,
  and (as Prof Ripley suggested) on purpose we're not taking other
  global par() settings for drawing of the axis() line {and the box() around!}.

Consider e.g.

  > nP <- names(par(no.readonly = TRUE))

  > nP[grep("^col",nP)]
  [1] "col"      "col.axis" "col.lab"  "col.main" "col.sub" 

  > nP[grep("axis",nP)]
  [1] "cex.axis"  "col.axis"  "font.axis"
  > 

then,
  > example(axis)

and,

  > plot(1:10, col.axis = "red", cex.axis = 2)

which does use double-sized axis *labels* in red.
If you read help(par), you'll see that the *.axis parameters are
used for axis *annotation* only.
One thing which would not break back-compatibility  I could
imagine is to introduce more par attributes:

  "col.axline"
  "lwd.axline"
  "lty.axline"
and default the axis() arguments to these.

Further, the box(lty = ) {and implicit "lwd" and "col") arguments would
also need new par() defaults {or have to default to the the
above *.axline ones}.

Finally, one might consider yet another set of par()s and
high-level plot arguments :

"col.ALL", "lty.ALL" , "lwd.ALL"
(and "cex.ALL" ?)  would change all the  col.* {or lty.* or ...}
at once.

Not sure these additions (and entailing complications) are
worth the effort.

--

Martin Maechler <maechler@stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><