R/bartest.multivar.R

Defines functions bartest.multivar

Documented in bartest.multivar

bartest.multivar <- function(dataset, group, measures = NULL, title = NULL){

  g.name <- (as.character(substitute(group)[[3]]))

  if(!is.null(measures))
  {
    dataset <- dataset[, measures]
    if(!g.name %in% measures)
    {
      dataset <- cbind(dataset, group)
      names(dataset)[names(dataset) == 'group'] <- g.name
    }

  }

  dataset <- dataset[!is.na(group), ]

  reshaped <- reshape::melt(dataset, id=g.name)
  names(reshaped)[names(reshaped) == colnames(reshaped)[1]] <- 'Group'

  SE <- Rmisc::summarySE(reshaped, measurevar="value", groupvars=c("Group", "variable"), na.rm=T)

  if(!is.null(title)) {title <- title}

  P <- ggplot2::ggplot(SE, aes(x=variable, y=value, group=Group, color=Group)) +
    geom_errorbar(aes(ymin=value-se, ymax=value+se), width=.2, position=position_dodge(.8)) +
    labs(x = "", y = "value", title = title)  +
    guides(fill=F) +
    geom_bar(position="dodge", stat="identity") +
    theme(plot.title = element_text(size = rel(1)))  +
    theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
    theme(panel.background = element_rect(fill = "White"))

  print(P)
}
# bartest.multivar(dataset = mtcars, group = mtcars$vs,
                             # measures = c('mpg', 'cyl', 'disp', 'hp'))
alemiani/explora documentation built on May 28, 2019, 4:54 p.m.