R/rankabunplot.R

Defines functions `rankabunplot`

`rankabunplot` <-
function(xr, addit=F, labels="", 
    scale="abundance",scaledx=F,type="o",
    xlim=c(min(xpos),max(xpos)),
    ylim=c(0,max(x[,scale])),
    specnames=c(1:5), srt=0, ...) {
    x <- xr
    xpos <- 1:nrow(x)
    if (scaledx==T) {xpos <- xpos/nrow(x)*100}
    if (scale=="accumfreq") {type <- "o"}
    if (addit==F) {
        if (scale == "logabun") {
            if (all.equal(ylim, c(0, max(x[,scale]))) == T) {ylim <- c(1, max(x[, "abundance"]))}
            graphics::plot(xpos, x[,"abundance"], xlab="species rank", ylab="abundance", type=type, bty="l", log="y", xlim=xlim, ylim=ylim, ...)
        }else{
            graphics::plot(xpos, x[,scale], xlab="species rank", ylab=scale, type=type, bty="l", ylim=ylim, xlim=xlim,...)
        }
    }else{
        if (scale=="logabun") {
            graphics::points(xpos,x[,"abundance"], type=type,...)
        }else{
            graphics::points(xpos,x[,scale], type=type,...)
        }
    }
    if (length(specnames) > 0) {
        names.space <- paste0("  ", rownames(x))
        for (i in specnames) {
            if (scale=="logabun") {
                graphics::text(i, x[i, "abundance"], names.space[i], pos=4, srt=srt, offset=0, adj=1)
            }else{
                graphics::text(i, x[i, scale], names.space[i], pos=4, srt=srt, offset=0, adj=1)
            }
        }
    }
    if (labels!="") {
            if (scale=="logabun") {
                graphics::text(1, x[1,"abundance"], labels=labels, pos=2)
            }else{
                graphics::text(1, x[1,scale], labels=labels, pos=2)
            }
    }
}

Try the BiodiversityR package in your browser

Any scripts or data that you put into this service are public.

BiodiversityR documentation built on June 22, 2024, 11:57 a.m.