drawBoxPlot: draw a custom box and whisker plot

View source: R/np_plotting_functions.R

drawBoxPlotR Documentation

draw a custom box and whisker plot

Description

takes a date frame with columns labeled 'at', 'q1', 'q3', 'min', 'max', 'median' and 'width' to draw a series of boxplots.

Usage

drawBoxPlot(
  x,
  col = "black",
  fill = NULL,
  drawBox = T,
  drawDot = F,
  whiskerLty = 2,
  side = FALSE,
  lWidth = 1,
  capWidth = 0.25,
  capType = "bar"
)

Arguments

x

named list or data frame; x$at, x$q2, x$q4, x$median, x$min, x$max and x$width must all be defined as numeric vectors in a named list or data.frame object.

col

character; color vector that controls the line color.

fill

character; color vector that determines the interior color of the box.

drawBox

logical; draws the box and whiskers if set to TRUE. The median line will be drawn regardless.

drawDot

logical; draws a circle at the center of the median bar if set to TRUE.

whiskerLty

positive integer; sets the line type or lty option for plotting the whiskers.

side

logical; if set to TRUE, the box plots will be drawn horizontally.

lWidth

positive integer; corresponds to lwd line width setting in base R.

capWidth

numeric; size of the error bar cap relative to the box width.

capType

character; should be equal to none, bar, or ball. Controls how the caps are drawn for the box plot whiskers.

Details

The input data frame x should include columns labels named 'at','q1',and 'q3', 'median', 'min', 'max' and 'width' in any order. Each row will draw a box and whisker plot. The columns 'q1' and 'q3' refer to the 25% and 75% cumulative distribution values that bound the interquartile range. If side=TRUE then the x and y axises are swapped to support horizontal plotting. The box and whiskers can be suppressed leaving only the median line and the optional center marker if so desired.

See Also

boxplot, niceBox

Examples

data(iris)
library(dplyr)
iData<-iris %>% group_by(Species) %>%
   summarize(median=median(Sepal.Length),min=min(Sepal.Length),max=max(Sepal.Length),
   q1=quantile(Sepal.Length)[2],q3=quantile(Sepal.Length)[4]) %>%
   bind_cols(at=c(1:3),width=c(.2,.3,.4))
plot(1,1,type="n",xlim=c(0,4),ylim=c(0,9))
#\donttest{drawBoxPlot(iData)}

ZachHunter/NicePlots.R documentation built on Sept. 23, 2023, 4:04 a.m.