A Boxplot Function With Embedded Statistical Tests for Comparing Groups

Share:

Description

A function which creates boxplots side-by-side, with points overlaid, to compare groups. Group sizes and p-values from tests comparing groups can be printed on the plot.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
   GroupListBoxplot(dataList, ymaxBoxplot=NA,addToYmax2=.2,addToYmax1=.1,boxWidth=.10,boxColor=8,
    boxOutliers=TRUE,groupColorVector=c(2,4,5,6,7,9,3,10,11,8,1),boxlty=1,boxlwd=1, 
    medlty=1,medlwd=3,medpch=NA, medcex=NA, legendInclude=TRUE,
    legendGroupNames=paste("Group ", 1:length(dataList),sep=""),legendX=NA,legendY=NA,legendCEX=1,
    legendPCH=1,legendColors=1:length(legendGroupNames),legendLTY=NA,legendLWD=NA,legendTitle=NA,
    legendPoints=TRUE,legendLines=FALSE,printPoints=TRUE,pointChar=1,pointCEX=1,
    pointColor=1:length(legendGroupNames),pointJitter=.25,mainTitle="Boxplots", mainTitleCEX=1,
    mainTitleFont=1,mainTitleLine=1,testTitleCEX=1,testTitleFont=1,testTitleLine=0,xlabel="X Axis",
    ylabel="Y Axis",xylabelsCEX=1,xylabelsFont=1,xAxisLabels=NA,xAxisCEX=1, xAxisFont=1,
    xAxisRotation=1,xMtext="",xMtextCEX=1,xMtextFont=1,xAtMtext=0,yAxisCEX=1,yAxisFont=1,
    yAxisRotation=1,plotBoxLWD=1,testsRoundDigits=2,pCEX=1,pFont=1,yP=NA,pvalueLabel="p",
    betweenGroupTestsCompute=TRUE,pairedGroups=FALSE,printNs=TRUE,nCEX=1,nFont=1,yN=NA)

Arguments

dataList

A list of data frames. Each data frame contains the data for a group. Each column in the data frame represents a time point or category point on the plot.

ymaxBoxplot

ymax for the boxplot will be set by R's boxplot() fcn, unless set here, default=NA

addToYmax2

this value is added to ymax if printing p-vals and N's, default=.2

addToYmax1

this value is added to ymax if only printing p-vals or N's, default=.1

boxWidth

width of the box, default=.10

boxColor

color of the box, default=8

boxOutliers

print or suppress outlier points on the plot, default=TRUE

groupColorVector

Vector of unique colors for a set of up to 11 groups, default=c(2,4,5,6,7,9,3,10,11,8,1)

boxlty

Box outline type, default=1

boxlwd

Box outline width, default=1

medlty

median line type, default=1

medlwd

median line width, default=3

medpch

median point character, default=NA

medcex

median point size expansion, default=NA

legendInclude

Print legend on plot, default=TRUE

legendGroupNames

names to use in the legend items, default=paste("Group ", 1:length(dataList), sep="")

legendX

legend X location, default=NA

legendY

legend Y location, default=NA

legendCEX

point size for legend text, default=1

legendPCH

symbol or character to print next to legend names, default=1

legendColors

colors of the points or lines next to the legend names, default=1:length(legendGroupNames)

legendLTY

line type to print next to legend names, default=NA

legendLWD

width of line to print next to legend names, default=NA

legendTitle

legend title, default=NA

legendPoints

print points next to legend names, default=TRUE

legendLines

print lines next to legend names, default=FALSE

printPoints

overlay the points on the boxplot, default=TRUE

pointChar

symbol or character to plot, default=1

pointCEX

size of point plotted, default=1

pointColor

color of point plotted – can be single value, vector, matrix, or list, default=1:length(legendGroupNames)

pointJitter

amount to scatter points around group x position, default=.25

mainTitle

text for main title, default="Boxplots"

mainTitleCEX

size of main title, default=1

mainTitleFont

regular or bold font, default=1

mainTitleLine

margin line on which to print main title - minimum is 0, default=1

testTitleCEX

size of stat test title, default=1

testTitleFont

regular or bold font, default=1

testTitleLine

margin line on which to print title - minimum is 0, default=0

xlabel

label for X axis, default="X Axis"

ylabel

label for Y axis, default="Y Axis"

xylabelsCEX

size of x and y axes labels, default=1

xylabelsFont

regular or bold font for X and Y axes labels, default=1

xAxisLabels

labels for ticks on x axis, default=NA

xAxisCEX

size of labels on x ticks, default=1

xAxisFont

regular or bold font for x tick labels, default=1

xAxisRotation

horizontal or vertical x tick labels, default=1

xMtext

text to place in x-axis margin, default=""

xMtextCEX

size of text to place in x-axis margin, default=1

xMtextFont

regular or bold font for text in x-axis margin, default=1

xAtMtext

x position for text in x-axis margin, size of y tick labels, default=0

yAxisCEX

size of y tick labels, default=1

yAxisFont

regular or bold font for y axis tick labels, default=1

yAxisRotation

horizontal or vertical y tick labels, default=1

plotBoxLWD

line width of box drawn around entire plot, default=1

testsRoundDigits

number of digits to report in p-value, default=2

pCEX

size of p-value text, default=1

pFont

regular or bold font for p-value text, default=1

yP

y position for p-value text, default=NA

pvalueLabel

label to use to precede numerical p-value, default="p"

betweenGroupTestsCompute

include group comparison p-values in plots, default=TRUE

pairedGroups

are the groups paired?, default=FALSE

printNs

include sample sizes on plots, default=TRUE

nCEX

size of the sample size text to print, default=1

nFont

regular or bold text for n's, default=1

yN

y position for the sample size text, default=NA

Author(s)

N. Hawkins, Fred Hutchinson Cancer Research Center, Seattle, WA

See Also

boxplot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Create Sample dataList
group1DataFrame = as.data.frame(cbind(1:3,4:6))
group2DataFrame = as.data.frame(cbind(4:6,7:9))
dataList = list(group1DataFrame, group2DataFrame) 

# Make the plot
GroupListBoxplot(dataList, xlabel="Cytokine", ylabel="Percent of CD4 Cells", 
   xAxisLabels=c("IFNg","TNFa"), mainTitle="Compare Innate Immune Response", 
   legendGroupNames=c("Group 1","Group 2"))

## -- Adults vs. Neonates Data -----------------------------------

## Marginal Data boxplot

# Get the data
data(marginalDF)
marginalDataSubset = subset(marginalDF, stim=="LPS" & concGroup==3 & cell=="mDC")
dataList = makeDataList(marginalDataSubset, "group", 1:5) 

# Make the group boxplot of marginal data
GroupListBoxplot(dataList, xlabel="Cytokine", ylabel="Percent of All Cells", 
   xAxisLabels=c("TNFa","IL6","IL12","IFNa","AnyMarker"), 
   mainTitle="Stimulation = LPS and Concentration Group = 3 and Cell = mDC", 
   legendGroupNames=c("Adults","Neonates"), pointColor=c(2,4), testTitleCEX=.8, nCEX=.8, 
   pCEX=.8, legendColor=c(2,4), legendCEX=.7)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.