[Rd] Minor bug: plot.table and Axis.table (partially) ignore graphical parameters (patch included)

Martin Becker martin.becker at mx.uni-saarland.de
Tue Apr 17 12:13:45 CEST 2012


Dear developers,

currently (rev 59060), plot.table and Axis.table do not forward their 
'...' argument to their calls to axis(). Thus, some graphical parameters 
(such as col.axis, cex.axis, font.axis) in '...' are ignored (for 
plot.table: partially ignored [for the x-axis]), which seems to be a 
minor bug. As a minimal reproducible example, see e.g.:

   plot(table(rbinom(100,5,0.5)), col.axis="red", cex.axis=2, font.axis=2)

Apparently, this behaviour is mainly caused by a suboptimal 
implementation of (undocumented) support for the logical parameter 
'axes' in plot.table's as well as Axis.table's '...' argument.

I propose to change the implementation as follows:
- make 'axes' an explicit argument of plot.table (as in plot.default, 
with default TRUE)
- drop support for the 'axes' flag in Axis.table's '...' argument (which 
is neither documented nor supported by other Axis.* functions AFAICS)
- in plot.table and Axis.table, forward '...' to axis() (in plot.table: 
"filtered" via a localaxis()-function similar to localAxis() in 
plot.default)

This would remove the minor bug and simplify the code. As a downside, 
the change breaks code which uses 'axes' as '...'-argument in a call to 
Axis.table(). But, as already mentioned, this is neither documented nor 
working for other methods of Axis.

So, please consider applying the attached (not fully tested, but 
trivial) patch.

Thank you and best wishes,
Martin

-- 
Dr. Martin Becker, Akad. Rat
Statistics and Econometrics
Saarland University
Campus C3 1, Room 217
66123 Saarbruecken
Germany

-------------- next part --------------
diff -rupN rev59060/trunk/src/library/graphics/R/axis.R patched/trunk/src/library/graphics/R/axis.R
--- rev59060/trunk/src/library/graphics/R/axis.R	2012-04-17 10:18:28.054985800 +0200
+++ patched/trunk/src/library/graphics/R/axis.R	2012-04-17 10:22:01.636201900 +0200
@@ -54,10 +54,7 @@ Axis.table <- function(x, at, ..., side
          x0 <- if (is.num) xx else seq.int(x)
          if(missing(at)) at <- x0
          if(missing(labels)) labels <- nx
-         xaxt <- if (length(as <- list(...))) {
-             if (!is.null(as$axes) && !as$axes) "n" else as$xaxt
-         }## else NULL
-         axis(side, at = at, labels = labels, xaxt = xaxt)
+         axis(side, at = at, labels = labels, ...)
      }
      else stop("only for 1-D table")
 }
diff -rupN rev59060/trunk/src/library/graphics/R/plot.R patched/trunk/src/library/graphics/R/plot.R
--- rev59060/trunk/src/library/graphics/R/plot.R	2012-04-17 10:19:16.492756300 +0200
+++ patched/trunk/src/library/graphics/R/plot.R	2012-04-17 12:01:06.404223200 +0200
@@ -105,8 +105,9 @@ plot.factor <- function(x, y, legend.tex
 ##   - if "h", make the default lwd depend on number of classes instead of lwd=2
 plot.table <-
     function(x, type = "h", ylim = c(0, max(x)), lwd = 2,
-             xlab = NULL, ylab = NULL, frame.plot = is.num, ...)
+             xlab = NULL, ylab = NULL, frame.plot = is.num, axes = TRUE, ...)
 {
+    localaxis <- function(..., col, bg, pch, cex, lty, lwd) axis(...)
     xnam <- deparse(substitute(x))
     rnk <- length(dim(x))
     if(rnk == 0L) stop("invalid table 'x'")
@@ -121,11 +122,7 @@ plot.table <-
 	plot(x0, unclass(x), type = type,
 	     ylim = ylim, xlab = xlab, ylab = ylab, frame.plot = frame.plot,
 	     lwd = lwd, ..., xaxt = "n")
-	xaxt <-
-	    if(length(as <- list(...))) {
-		if(!is.null(as$axes) && !as$axes) "n" else as$xaxt
-	    }## else NULL
-	axis(1, at = x0, labels = nx, xaxt = xaxt)
+	if (axes) localaxis(1, at = x0, labels = nx, ...)
     } else {
 	if(length(as <- list(...)) && !is.null(as$main)) # use 'main'
 	    mosaicplot(x, xlab = xlab, ylab = ylab, ...)
diff -rupN rev59060/trunk/src/library/graphics/man/plot.table.Rd patched/trunk/src/library/graphics/man/plot.table.Rd
--- rev59060/trunk/src/library/graphics/man/plot.table.Rd	2012-04-17 10:47:26.492418700 +0200
+++ patched/trunk/src/library/graphics/man/plot.table.Rd	2012-04-17 10:48:53.812413100 +0200
@@ -16,7 +16,7 @@
 }
 \usage{
 \method{plot}{table}(x, type = "h", ylim = c(0, max(x)), lwd = 2,
-     xlab = NULL, ylab = NULL, frame.plot = is.num, \dots)
+     xlab = NULL, ylab = NULL, frame.plot = is.num, axes = TRUE, \dots)
 \method{points}{table}(x, y = NULL, type = "h", lwd = 2, \dots)
 \method{lines}{table}(x, y = NULL, type = "h", lwd = 2, \dots)
 }
@@ -30,6 +30,9 @@
   \item{frame.plot}{logical indicating if a frame (\code{\link{box}})
     should be drawn in the 1D case.  Defaults to true when \code{x} has
     \code{\link{dimnames}} coerce-able to numbers.}
+  \item{axes}{a logical value indicating whether both axes should be drawn on
+    the plot.  Use \link{graphical parameter} \code{"xaxt"} or \code{"yaxt"}
+    to suppress just one of the axes.}
   \item{\dots}{further graphical arguments, see \code{\link{plot.default}}.}
 }
 \seealso{


More information about the R-devel mailing list