#' @name bar.err
#' @aliases bar.err
#' @title Plotting the standard error or standard deviance of a multiple comparison of means
#' @description
#' It plots bars of the averages of treatments and standard error or standard
#' deviance. It uses the objects generated by a procedure of comparison like
#' LSD, HSD, Kruskal and Waller-Duncan.
#'
#' x: data frame formed by 5 columns: name of the bars, height, level out:
#' LSD.test, HSD, waller.test, scheffe.test, duncan.test, SNK.test, friedman,
#' kruskal, waerden.test and Median.test.
#'
#' @param x object means of the comparisons the LSD.test, HSD.test,...,etc
#' @param variation SE=standard error, range=Max-Min or IQR=interquartil range
#' @param horiz Horizontal or vertical bars
#' @param bar paint bar
#' @param \dots Parameters of the function barplot()
#'
#' @return A list with numeric vectors giving the coordinates of all the bar
#' midpoints drawn.
#' @return \strong{x} eje-1 coordinate
#' @return \strong{height} eje-2 coordinate by group
#'
#' @author
#' \enumerate{
#' \item Felipe de Mendiburu (\email{fmendiburu@@lamolina.edu.pe})
#' \item Muhammad Yaseen (\email{myaseen208@@gmail.com})
#' }
#'
#' @seealso
#'
#' \code{\link{LSD.test}}, \code{\link{HSD.test}},
#' \code{\link{waller.test}}, \code{\link{kruskal}}, \code{\link{bar.group}}
#'
#'
#' @keywords aplot
#'
#'
#' @importFrom graphics barplot lines text
#' @export
#'
#' @examples
#'
#' library(agricolae)
#' data(sweetpotato)
#' model<-aov(yield~virus,data=sweetpotato)
#' out <- waller.test(model,"virus", console=TRUE,
#' main="Yield of sweetpotato\ndealt with different virus")
#' oldpar<-par(mfrow=c(2,2),cex=1)
#' bar.err(out$means,variation="range",horiz=TRUE,xlim=c(0,45),angle=125,density=6,
#' main="range")
#' bar.err(out$means,variation="SD",ylim=c(0,45),col=colors()[30],
#' main="Standard deviation",density=8)
#' bar.err(out$means,variation="SE",horiz=TRUE,xlim=c(0,45),density=8,
#' col="brown",main="Standard error")
#' bar.err(out$means,variation="range",ylim=c(0,45),bar=FALSE,col="green",
#' main="range")
#' par(mfrow=c(1,2),cex=1)
#' bar.err(out$means,variation="range",ylim=c(0,45),bar=FALSE,col=0)
#' abline(h=0)
#' # horiz = TRUE
#' bar.err(out$means,variation="SE",horiz=TRUE,xlim=c(0,45),bar=FALSE,col=0)
#' #startgraph
#' par(oldpar)
#' #endgraph
#'
bar.err <-
function(x,variation=c("SE","SD","range","IQR"),horiz=FALSE, bar=TRUE,...) {
UseMethod("bar.err")
}
#' @export
#' @rdname bar.err
bar.err.default <-
function(x,variation=c("SE","SD","range","IQR"),horiz=FALSE, bar=TRUE,...) {
variation<-match.arg(variation)
y<-x[,1]
names(y)<-rownames(x)
if( variation=="SE" ) {
if( "std"%in%names(x) & variation != "IQR") {
std.err<-x$"std"/sqrt(x$"r")
nivel0<-y-std.err
nivel1<-y+std.err
}
else return("For variation use IQR or range")
}
if( variation=="SD" ) {
if("std" %in% names(x)){
nivel0<-y-x$"std"
nivel1<-y+x$"std"
}
else return("For variation use IQR or range")
}
if( variation=="range" ) {
nivel0<-x$"Min"
nivel1<-x$"Max"
}
if( variation=="IQR") {
nivel0<-x$"Q25"
nivel1<-x$"Q75"
}
n<-length(y)
if (bar) {
indice<-barplot(y,horiz=horiz, ...)
tope<-max(nivel1)/20
}
else {
indice<-barplot(y,horiz=horiz, border=0, ...)
if(horiz)lines(y,indice,type="b")
else lines(indice,y,type="b")
}
for ( i in 1:n) {
if (horiz) {
lines(rbind(c(nivel0[i],indice[i]),c(nivel1[i],indice[i])))
text( cex=1,nivel0[i],indice[i],"[")
text( cex=1,nivel1[i],indice[i],"]")
}
else {
lines(rbind(c(indice[i],nivel0[i]),c(indice[i],nivel1[i])))
text( cex=1,indice[i],nivel0[i],"---")
text( cex=1,indice[i],nivel1[i],"---")
}
}
invisible(list(x=indice,height=y))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.