#' @name bar.group
#' @aliases bar.group
#' @title Plotting the multiple comparison of means
#' @description
#' It plots bars of the averages of treatments to compare. It uses the objects
#' generated by a procedure of comparison like LSD, HSD, Kruskall,
#' Waller-Duncan, Friedman or Durbin. It can also display the 'average' value
#' over each bar in a bar chart.
#'
#' x: data frame formed by 5 columns: name of the bars, height and level of the
#' bar.
#'
#' @param x Object created by a test of comparison
#' @param horiz Horizontal or vertical bars
#' @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{kruskal}} , \code{\link{friedman}}, \code{\link{durbin.test}},
#' \code{\link{waller.test}} , \code{\link{plot.group}}
#'
#' @keywords aplot
#'
#'
#' @importFrom graphics barplot lines text
#' @export
#'
#' @examples
#'
#' # Example 1
#' library(agricolae)
#' data(sweetpotato)
#' model<-aov(yield~virus,data=sweetpotato)
#' comparison<- LSD.test(model,"virus",alpha=0.01,group=TRUE)
#' print(comparison$groups)
#' oldpar<-par(cex=1.5)
#' bar.group(comparison$groups,horiz=TRUE,density=8,col="blue",border="red", xlim=c(0,50),las=1)
#' title(cex.main=0.8,main="Comparison between\ntreatment means",xlab="Yield",ylab="Virus")
#' # Example 2
#' library(agricolae)
#' x <- 1:4
#' y <- c(0.29, 0.44, 0.09, 0.49)
#' xy <- data.frame(x,y,y)
#' par(oldpar)
#' oldpar<-par(cex=1.5)
#' bar.group(xy,density=30,angle=90,col="brown",border=FALSE,ylim=c(0,0.6),lwd=2,las=1)
#' par(oldpar)
#'
bar.group <-
function(x,horiz=FALSE, ...) {
UseMethod("bar.group")
}
#' @export
#' @rdname bar.group
bar.group.default <-
function(x,horiz=FALSE, ...) {
y<-x[,1]
names(y)<-rownames(x)
nivel<-x[,2]
n<-length(y)
index<-barplot(y,horiz=horiz, ...)
tope<-max(y)/10
for ( i in 1:n) {
if (horiz) text(y[i]+tope,index[i],nivel[i])
else {
if (y[i]<0) text(index[i],abs(tope),nivel[i])
else text(index[i],y[i]+tope,nivel[i])
}
}
invisible(list(x=index,height=y))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.