scale.bar {biology}R Documentation

~~function to do ... ~~

Description

~~ A concise (1-5 lines) description of what the function does. ~~

Usage

scale.bar(s_x, s_y = NULL, len, ht, q = 2, cex = 1)

Arguments

s_x ~~Describe s_x here~~
s_y ~~Describe s_y here~~
len ~~Describe len here~~
ht ~~Describe ht here~~
q ~~Describe q here~~
cex ~~Describe cex here~~

Details

~~ If necessary, more details than the description above ~~

Value

~Describe the value returned If it is a LIST, use
comp1 Description of 'comp1'
comp2 Description of 'comp2'
...

Note

~~further notes~~

~Make other sections like Warning with Warning .... ~

Author(s)

~~who you are~~

References

~put references to the literature/web site here ~

See Also

~~objects to See Also as help, ~~~

Examples

##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (s_x, s_y = NULL, len, ht, q = 2, cex = 1) 
{
    require(sp)
    require(rgdal)
    if (is.null(s_y)) {
        scale_start <- data.frame(x = s_x$x, y = s_x$y)
    }
    else {
        scale_start <- data.frame(x = 145.9692, y = -34.47851)
        scale_start <- data.frame(x = s_x, y = s_y)
    }
    coordinates(scale_start) = ~x + y
    proj4string(scale_start) <- CRS("+proj=longlat +ellps=WGS84")
    scale_start.utm <- spTransform(scale_start, CRS("+proj=utm +zone=55 +south"))
    s_xx <- attr(scale_start.utm, "coords")[, "x"]
    s_yy <- attr(scale_start.utm, "coords")[, "y"]
    x_start <- s_xx
    x_end <- s_xx + len
    y_start <- s_yy
    y_end <- s_yy + ht
    scale_end <- data.frame(x = x_end, y = y_end)
    coordinates(scale_end) = ~x + y
    proj4string(scale_end) <- CRS("+proj=utm +zone=55 +south")
    scale_end.latlong <- spTransform(scale_end, CRS("+proj=longlat +ellps=WGS84"))
    s_x2 <- attr(scale_end.latlong, "coords")[, "x"]
    s_y2 <- attr(scale_end.latlong, "coords")[, "y"]
    horiz <- s_x2 - attr(scale_start, "coords")[, "x"]
    vert <- s_y2 - attr(scale_start, "coords")[, "y"]
    m <- NULL
    x <- c(0, 1/q, 1/q, 0, 0)
    for (i in 1:q) {
        m[[i]] <- matrix(0, nrow = 5, ncol = 2)
        m[[i]][, 1] <- attr(scale_start, "coords")[, "x"] + (x * 
            (horiz))
        m[[i]][, 2] <- c(attr(scale_start, "coords")[, "y"], 
            attr(scale_start, "coords")[, "y"], attr(scale_start, 
                "coords")[, "y"] + vert, attr(scale_start, "coords")[, 
                "y"] + vert, attr(scale_start, "coords")[, "y"])
        x <- x + (1/q)
        if (i == (as.integer(i/2) * 2)) 
            polygon(m[[i]], col = "black")
        else polygon(m[[i]], col = "white")
        lx <- m[[i]][1, 1]
        ly <- m[[i]][1, 2]
        lines(c(lx, lx), c(ly, ly + (2 * vert)))
        lines(c(m[[i]][3, 1], m[[i]][3, 1]), c(ly, ly + (2 * 
            vert)))
        text(lx, ly + (cex * vert), (i - 1) * ((len/1000)/q), 
            pos = 3, cex = cex)
        text(m[[i]][3, 1], ly + (cex * vert), (i) * ((len/1000)/q), 
            pos = 3, cex = cex)
    }
    text(attr(scale_start, "coords")[, "x"] + (0.5 * (horiz)), 
        attr(scale_start, "coords")[, "y"] + (cex * vert), "Kilometres", 
        pos = 1, cex = cex)
  }

[Package biology version 1.0 Index]