Skip to content
Prev 28494 / 63468 Next

graphics::Axis loosing S3/S4 class attributes of 'x' in 2.7.0 RC

Ok, so what's wrong with the following fix for plot(x) that would
actually fix what needs to be fixed instead of changing plot.default?
Fix means reverting plot.default in 2.7.0 to what it was (if testing in
2.7.0, copy and paste the OLD plot.default into the .GlobalEnv):

plot.POSIXct <- function(x, y, xlab = "", ...) {
    if (!missing(y)) {
        side = 1
        plotDef <- function(x, y, xaxt, xlab, ...) plot.default(x, y,
xaxt="n", xlab=xlab, ...)
        plotDef(x, y, xlab=xlab, ...)
    } else {
        side = 2
        plotDef <- function(x, y, yaxt, xlab, ...) plot.default(x, y,
yaxt="n", xlab=xlab, ...)
        plotDef(seq_along(x), x, xlab=xlab, ...)
    }
    ## trick to remove arguments intended for title() or plot.default()
    axisInt <- function(x, type, main, sub, xlab, ylab, col, lty, lwd,
                        xlim, ylim, bg, pch, log, asp, axes, frame.plot,
...)
        axis.POSIXct(side, x, ...)
    dots <- list(...)
    axes <- if("axes" %in% names(dots)) dots$axes else TRUE
    xaxt <- if("xaxt" %in% names(dots)) dots$xaxt else par("xaxt")
    if(axes && xaxt != "n") axisInt(x, ...)
}

plot.POSIXlt <- function(x, y, xlab = "", ...) {
    if (missing(y)) plot.POSIXct(as.POSIXct(x), xlab=xlab, ...)
    else plot.POSIXct(as.POSIXct(x), y=y, xlab=xlab, ...)
}

And try with:
x = Sys.time() + runif(100,1,7200)
plot(x)
plot(x,1:100)
plot(1:100,x)

plot(as.POSIXlt(x))
plot(as.POSIXlt(x),1:100)
plot(1:100,as.POSIXlt(x))


Dr Oleg Sklyar
Technology Group
Man Investments Ltd
+44 (0)20 7144 3803
osklyar at maninvestments.com