Learn R Programming

WGCNA (version 1.68)

verboseBarplot: Barplot with error bars, annotated by Kruskal-Wallis or ANOVA p-value

Description

Produce a barplot with error bars, annotated by Kruskal-Wallis or ANOVA p-value.

Usage

verboseBarplot(x, g, 
               main = "", xlab = NA, ylab = NA, 
               cex = 1, cex.axis = 1.5, cex.lab = 1.5, cex.main = 1.5, 
               color = "grey", numberStandardErrors = 1, 
               KruskalTest = TRUE, AnovaTest = FALSE, two.sided = TRUE, 
               addCellCounts=FALSE, horiz = FALSE, ylim = NULL, ...,
               addScatterplot = FALSE,
               pt.cex = 0.8, pch = 21, pt.col = "blue", pt.bg = "skyblue",
               randomSeed = 31425, jitter = 0.6,
               pointLabels = NULL,
               label.cex = 0.8,
               label.offs = 0.06,
               adjustYLim = TRUE)

Arguments

x

numerical or binary vector of data whose group means are to be plotted

g

a factor or a an object coercible to a factor giving the groups whose means are to be calculated.

main

main title for the plot.

xlab

label for the x-axis.

ylab

label for the y-axis.

cex

character expansion factor for plot annotations.

cex.axis

character expansion factor for axis annotations.

cex.lab

character expansion factor for axis labels.

cex.main

character expansion factor for the main title.

color

a vector giving the colors of the bars in the barplot.

numberStandardErrors

size of the error bars in terms of standard errors. See details.

KruskalTest

logical: should Kruskal-Wallis test be performed? See details.

AnovaTest

logical: should ANOVA be performed? See details.

two.sided

logical: should the printed p-value be two-sided? See details.

addCellCounts

logical: should counts be printed above each bar?

horiz

logical: should the bars be drawn horizontally?

ylim

optional specification of the limits for the y axis. If not given, they will be determined automatically.

other parameters to function barplot.

addScatterplot

logical: should a scatterplot of the data be overlaid?

pt.cex

character expansion factor for the points.

pch

shape code for the points.

pt.col

color for the points.

pt.bg

background color for the points.

randomSeed

integer random seed to make plots reproducible.

jitter

amount of random jitter to add to the position of the points along the x axis.

pointLabels

Optional text labels for the points displayed using the scatterplot. If given, should be a character vector of the same length as x. See labelPoints.

label.cex

Character expansion (size) factor for pointLabels.

label.offs

Offset for pointLabels, as a fraction of the plot width.

adjustYLim

logical: should the limits of the y axis be set so as to accomodate the individual points? The adjustment is only carried out if input ylim is NULL and addScatterplot is TRUE. In particular, if the user supplies ylim, it is not touched.

Value

None.

Details

This function creates a barplot of a numeric variable (input x) across the levels of a grouping variable (input g). The height of the bars equals the mean value of x across the observations with a given level of g. By default, the barplot also shows plus/minus one standard error. If you want only plus one standard error (not minus) choose two.sided=TRUE. But the number of standard errors can be determined with the input numberStandardErrors. For example, if you want a 95% confidence interval around the mean, choose numberStandardErrors=2. If you don't want any standard errors set numberStandardErrors=-1. The function also outputs the p-value of a Kruskal Wallis test (Fisher test for binary input data), which is a non-parametric multi group comparison test. Alternatively, one can use Analysis of Variance (Anova) to compute a p-value by setting AnovaTest=TRUE. Anova is a generalization of the Student t-test to multiple groups. In case of two groups, the Anova p-value equals the Student t-test p-value. Anova should only be used if x follows a normal distribution. Anova also assumes homoscedasticity (equal variances). The Kruskal Wallis test is often advantageous since it makes no distributional assumptions. Since the Kruskal Wallis test is based on the ranks of x, it is more robust with regard to outliers. All p-values are two-sided.

See Also

barplot

Examples

Run this code
# NOT RUN {
   group=sample(c(1,2),100,replace=TRUE)

   height=rnorm(100,mean=group)

   par(mfrow=c(2,2))
   verboseBarplot(height,group, main="1 SE, Kruskal Test")

   verboseBarplot(height,group,numberStandardErrors=2, 
                  main="2 SE, Kruskal Test")

   verboseBarplot(height,group,numberStandardErrors=2,AnovaTest=TRUE, 
                  main="2 SE, Anova")

   verboseBarplot(height,group,numberStandardErrors=2,AnovaTest=TRUE, 
                  main="2 SE, Anova, only plus SE", two.sided=FALSE)

# }

Run the code above in your browser using DataLab