Contour() should handle the asp parameter

From: Patrick Giraudoux (patrick.giraudoux@univ-fcomte.fr)
Date: Sun Dec 14 2003 - 16:08:25 MET


Suivant les conseils de Jean Lobry, j'ai donc envoyé à R-help une proposition de modification de contour.default (copie ci-dessous). Elle marche apparemment sans problème. Puisse le ciel et les professionnels de R ne pas me tomber sur la tête si ça déclenche un bug d'apocalypse qui m'aurait échappé...

Cordialement à tous,

Patrick Giraudoux

----- Original Message -----
From: Patrick Giraudoux
To: r-help@stat.math.ethz.ch
Sent: Sunday, December 14, 2003 3:58 PM
Subject: contour() should handle the asp parameter

Hi all,

To my knowledge, the current version of contour.default() does not handle the 'asp' parameter. This can be embarassing when displaying eg geographical maps, etc... Submitted to the opinion of more experienced R programmers, contour.defaut() function should be changed according to the followings:

line 7: add = FALSE,asp=NA,...)
line 33: plot.window(xlim, ylim, asp=asp,"")

The new script would be:

contour.default<-
function (x = seq(0, 1, len = nrow(z)), y = seq(0, 1,
len = ncol(z)),z, nlevels = 10, levels = pretty(zlim, nlevels), labels = NULL, xlim = range(x, finite = TRUE), ylim = range(y, finite = TRUE),
    zlim = range(z, finite = TRUE), labcex = 0.6, drawlabels = TRUE,
    method = "flattest", vfont = c("sans serif", "plain"), axes = TRUE,
    frame.plot = axes, col = par("fg"), lty = par("lty"), lwd = par("lwd"),
    add = FALSE,asp=NA,...)
{
    if (missing(z)) {
        if (!missing(x)) {
            if (is.list(x)) {
                z <- x$z
                y <- x$y
                x <- x$x
            }
            else {
                z <- x
                x <- seq(0, 1, len = nrow(z))
            }
        }
        else stop("no `z' matrix specified")
    }
    else if (is.list(x)) {
        y <- x$y
        x <- x$x
    }
    if (any(diff(x) <= 0) || any(diff(y) <= 0))
        stop("increasing x and y values expected")
    if (!is.matrix(z) || nrow(z) <= 1 || ncol(z) <= 1)
        stop("no proper `z' matrix specified")
    if (!add) {
        plot.new()
        plot.window(xlim, ylim, asp=asp,"")
        title(...)
    }
    if (!is.double(z))
        storage.mode(z) <- "double"
    method <- pmatch(method[1], c("simple", "edge", "flattest"))
    if (!is.null(vfont))
        vfont <- c(typeface = pmatch(vfont[1], Hershey$typeface) -
            1, fontindex = pmatch(vfont[2], Hershey$fontindex))
    if (!is.null(labels))
        labels <- as.character(labels)
    .Internal(contour(as.double(x), as.double(y), z, as.double(levels),
        labels, labcex, drawlabels, method, vfont, col = col,
        lty = lty, lwd = lwd))
    if (!add) {
        if (axes) {
            axis(1)
            axis(2)
        }
        if (frame.plot)
            box()
    }
    invisible()
}
<environment: namespace:base>

Best regards,

Patrick



This archive was generated by hypermail 2b30 : Tue Sep 07 2004 - 13:45:27 MEST