bargraph {biology} | R Documentation |
~~ A concise (1-5 lines) description of what the function does. ~~
bargraph(dv, iv, grp = NULL, width = 1, space = 0.5, ymin, xmin = 0, ymax, xlabs = c("N"), xmax, xlab, ylab1, ylab2, ylabs = c("N"), xlabelsfontsize = 1, ylabelsfontsize = 1, ytitlefontsize, ylabpos = 4, sublabel = c(""), plotting = T, legnd, errorbars = "None", ...)
dv |
~~Describe dv here~~ |
iv |
~~Describe iv here~~ |
grp |
~~Describe grp here~~ |
width |
~~Describe width here~~ |
space |
~~Describe space here~~ |
ymin |
~~Describe ymin here~~ |
xmin |
~~Describe xmin here~~ |
ymax |
~~Describe ymax here~~ |
xlabs |
~~Describe xlabs here~~ |
xmax |
~~Describe xmax here~~ |
xlab |
~~Describe xlab here~~ |
ylab1 |
~~Describe ylab1 here~~ |
ylab2 |
~~Describe ylab2 here~~ |
ylabs |
~~Describe ylabs here~~ |
xlabelsfontsize |
~~Describe xlabelsfontsize here~~ |
ylabelsfontsize |
~~Describe ylabelsfontsize here~~ |
ytitlefontsize |
~~Describe ytitlefontsize here~~ |
ylabpos |
~~Describe ylabpos here~~ |
sublabel |
~~Describe sublabel here~~ |
plotting |
~~Describe plotting here~~ |
legnd |
~~Describe legnd here~~ |
errorbars |
~~Describe errorbars here~~ |
... |
~~Describe ... here~~ |
~~ If necessary, more details than the description above ~~
~Describe the value returned If it is a LIST, use
comp1 |
Description of 'comp1' |
comp2 |
Description of 'comp2' |
...
....
~~further notes~~
~Make other sections like Warning with section{Warning }{....} ~
~~who you are~~
~put references to the literature/web site here ~
~~objects to See Also as help
, ~~~
##---- 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 (dv, iv, grp = NULL, width = 1, space = 0.5, ymin, xmin = 0, ymax, xlabs = c("N"), xmax, xlab, ylab1, ylab2, ylabs = c("N"), xlabelsfontsize = 1, ylabelsfontsize = 1, ytitlefontsize, ylabpos = 4, sublabel = c(""), plotting = T, legnd, errorbars = "None", ...) { old.par <- par(no.readonly = T) on.exit(par(old.par)) if (missing(ylab1)) ylab1 <- deparse(substitute(dv)) if (missing(ylab2)) ylab2 <- "" if (missing(grp)) { means <- tapply(dv, iv, mean) stdev <- tapply(dv, iv, sd) n <- tapply(dv, iv, length) sterr <- stdev/sqrt(n) if (missing(xlab)) xlab <- deparse(substitute(iv)) legnd <- NULL } else { means <- tapply(dv, list(grp, iv), mean) stdev <- tapply(dv, list(grp, iv), sd) n <- tapply(dv, list(grp, iv), length) sterr <- stdev/sqrt(n) if (missing(xlab)) xlab <- deparse(substitute(iv)) if (missing(legnd)) legnd <- c(levels(grp)) } if (ymax == "NULL") { if (errorbars == "se") { y.heights <- means + sterr + ((means + sterr) * 0.05) } else if (errorbars == "sd") { y.heights = means + stdev + ((means + stdev) * 0.05) } else y.heights = means ymax <- max(y.heights) } if (ymin == "NULL") { ymin <- 0 } y <- seq(ymin, ymax, by = ymax/5) yy <- seq(ymin, ymax, by = ymax/25) if (ylabs == "N") ylabs <- seq(ymin, ymax, by = ymax/5) if (plotting == F) barcolor <- c("white") if (plotting == F) means <- c(0, 0) par(lwd = 2) x <- barplot(means, ylab = "", axes = FALSE, ylim = c(ymin, ymax), width = width, axisnames = FALSE, beside = T, xpd = F, legend.text = legnd, ) if (errorbars == "se") { if (plotting == T) arrows(x, means, x, means - sterr, angle = 90, length = 0.05, lwd = 2) if (plotting == T) arrows(x, means, x, means + sterr, angle = 90, length = 0.05, lwd = 2) } else if (errorbars == "sd") { if (plotting == T) arrows(x, means, x, means - stdev, angle = 90, length = 0.05, lwd = 2) if (plotting == T) arrows(x, means, x, means + stdev, angle = 90, length = 0.05, lwd = 2) } axis(2, las = 1, lwd = 2, cex.axis = ylabelsfontsize, font = 2) if (missing(grp)) { x <- c(0.02, x) xlabs <- levels(iv) } else { xlabs <- levels(iv) xleg <- max(x) xx <- split(x, gl(length(levels(iv)), length(levels(grp)))) xx <- sapply(xx, mean) x <- c(0.02, xx) } print(xlabs) xlabs <- c("", xlabs) axis(1, at = x, pos = ymin, labels = xlabs, lwd = 2, cex.axis = xlabelsfontsize, tick = TRUE, font = 2) mtext(ylab1, 2, line = 3, font = 2, cex = 1.5) mtext(ylab2, 2, line = 2.2, font = 2, cex = 1.5) mtext(xlab, 1, line = 3, font = 2, cex = 1.5) par(old.par) x }