https://github.com/cran/fields
Raw File
Tip revision: 6c8b30169bba182a68765ee3cb9b4e2ef7d38332 authored by Doug Nychka on 16 November 2011, 00:00:00 UTC
version 6.6.3
Tip revision: 6c8b301
colorbar.plot.R
# fields, Tools for spatial data
# Copyright 2004-2011, Institute for Mathematics Applied Geosciences
# University Corporation for Atmospheric Research
# Licensed under the GPL -- www.gpl.org/licenses/gpl.html
"colorbar.plot" <- function(x, y, strip, strip.width = 0.1, 
    strip.length = 4 * strip.width, zrange = NULL, adj.x = 0.5, 
    adj.y = 0.5, col = tim.colors(256), horizontal = TRUE, ...) {
    # coerce to be one column matrix if it is a vector
    if (!is.matrix(strip)) {
        strip <- matrix(c(strip), ncol = 1)
    }
    m <- nrow(strip)
    n <- ncol(strip)
    # find common range across strips if not specified
    if (is.null(zrange)) {
        zrange <- matrix(range(c(strip), na.rm = TRUE), nrow = n, 
            ncol = 2, byrow = TRUE)
    }
    # see help( par) for background on graphical settings
    ucord <- par()$usr
    pin <- par()$pin
    if (horizontal) {
        dy <- strip.width * (ucord[4] - ucord[3])
        dx <- strip.length * pin[2] * (ucord[2] - ucord[1])/(pin[1])
    }
    else {
        dx <- strip.width * (ucord[2] - ucord[1])
        dy <- strip.length * pin[1] * (ucord[4] - ucord[3])/(pin[2])
    }
    #
    # dx and dy should have the correct ratio given different different scales
    # and also different aspects to the plot window
    #
    n <- ncol(strip)
    m <- nrow(strip)
    # create grids in x and y for strip(s) based on the users
    # coordinates of the plot and th positioning argument (adj)
    if (horizontal) {
        xs <- seq(0, dx, , m + 1) + x - adj.x * dx
        ys <- seq(0, dy, , n + 1) + y - adj.y * dy
    }
    else {
        xs <- seq(0, dx, , n + 1) + x - adj.x * dx
        ys <- seq(0, dy, , m + 1) + y - adj.y * dy
    }
    #
    # plot image row by row to allow for different zlim's
    # see image.add for a fields function that just plots the whole image at
    # once.
    for (k in 1:n) {
        if (horizontal) {
            image(xs, c(ys[k], ys[k + 1]), cbind(strip[, k]), 
                zlim = zrange[k, ], add = TRUE, col = col, ...)
        }
        else {
            image(c(xs[k], xs[k + 1]), ys, rbind(strip[, k]), 
                zlim = zrange[k, ], add = TRUE, col = col, ...)
        }
    }
}
back to top