Mbargraph {biology} | R Documentation |
~~ A concise (1-5 lines) description of what the function does. ~~
Mbargraph(dv, factorlist, ylabel = paste("Mean", deparse(substitute(dv))), xlabel = "", type = "b", ymin = NULL, ymax = NULL, errorbars = "se", symbols = "")
dv |
~~Describe dv here~~ |
factorlist |
~~Describe factorlist here~~ |
ylabel |
~~Describe ylabel here~~ |
xlabel |
~~Describe xlabel here~~ |
type |
~~Describe type here~~ |
ymin |
~~Describe ymin here~~ |
ymax |
~~Describe ymax here~~ |
errorbars |
~~Describe errorbars here~~ |
symbols |
~~Describe symbols 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 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, factorlist, ylabel = paste("Mean", deparse(substitute(dv))), xlabel = "", type = "b", ymin = NULL, ymax = NULL, errorbars = "se", symbols = "") { means <- tapply(dv, factorlist, mean, na.rm = T) sds <- tapply(dv, factorlist, sd, na.rm = T) ns <- tapply(dv, factorlist, function(x) length(na.omit(x))) ses <- sds/sqrt(ns) ys <- pretty(c(means - ses, means + (2 * ses))) if (!is.null(ymin)) ys <- c(ys, ymin) if (!is.null(ymax)) ys <- c(ys, ymax) if (type == "b") { if (is.list(factorlist)) { xs <- barplot(means, ylim = c(min(ys), max(ys)), beside = T, axes = F, xpd = F, axisnames = T, axis.lty = 2, legend.text = T) if (xlabel == "") { xlabel = deparse(substitute(factorlist)[[3]]) } } else { xs <- barplot(means, ylim = c(min(ys), max(ys)), beside = T, axes = F, xpd = F, axis.lty = 1, legend.text = F) if (xlabel == "") { xlabel = deparse(substitute(factorlist)) } } } else { if (is.list(factorlist)) { xs <- barplot(means, ylim = c(min(ys), max(ys)), beside = T, axes = F, xpd = F, axis.lty = 1, legend.text = F, plot = FALSE) interaction.plot(factorlist[[1]], factorlist[[2]], dv, ylim = c(min(ys), max(ys))) } else { xs <- plotMeans(means, factorlist[[1]], factorlist[[2]]) } } library(Hmisc) errbar(xs, means, means + ses, means - ses, add = T) axis(2, las = 1) mtext(2, text = ylabel, line = 3, cex = 1.5) mtext(1, text = xlabel, line = 3, cex = 1.5) lines(c(0, max(xs) + 0.5), c(min(ys), min(ys))) Mgraph <- data.frame(xs, means = means + ses + ((max(ys) - min(ys))/20)) if (exists("symbols")) { text(xs, means + ses, labels = symbols, pos = 3) } }