Package 'qboxplot'

Title: Quantile-Based Boxplot
Description: Produce quantile-based box-and-whisker plot(s).
Authors: Tom Pike
Maintainer: Tom Pike <[email protected]>
License: GPL-2
Version: 0.2
Built: 2024-11-13 02:56:54 UTC
Source: https://github.com/cran/qboxplot

Help Index


Quantile-Based Boxplots

Description

Produce quantile-based box-and-whisker plot(s) of the given (grouped) values.

Usage

qboxplot(x, range=1.5, probs=c(0.25,0.5,0.75), qtype=7, data=parent.frame(),
         width=NULL, varwidth=FALSE, outline=TRUE, names=NULL, plot=TRUE,
         border=par("fg"), col=NULL, log="", pars=list(boxwex=0.8,
         staplewex=0.5, outwex=0.5), horizontal=FALSE, add=FALSE, at=NULL,
         ...)

Arguments

x

a formula, such as y ~ grp, where y is a numeric vector of data values to be split into groups according to the grouping variable grp (usually a factor), or a data frame specifying data from which the boxplots are to be produced.

range

this determines how far the plot whiskers extend out from the box. If range is positive, the whiskers extend to the most extreme data point which is no more than range times the difference between the value of the upper hinge and the value of the lower hinge from the box. A value of zero causes the whiskers to extend to the data extremes.

probs

numeric vector of values in [0,1] specifying the percentiles of the upper hinge, the midpoint (usually the median) and the lower hinge.

qtype

an integer between 1 and 9 indicating which one of the nine quantile algorithms to use (see quantile).

data

a data.frame (or list) from which the variables in formula should be taken.

width

a vector giving the relative widths of the boxes making up the plot.

varwidth

if varwidth is TRUE, the boxes are drawn with widths proportional to the square-roots of the number of observations in the groups.

outline

if outline is FALSE, the outliers are not drawn.

names

group labels which will be printed under each boxplot.

plot

if TRUE then a boxplot is produced. If not, the summaries which the boxplots are based on are returned.

border

an optional vector of colours for the outlines of the boxplots. The values in border are recycled if the length of border is less than the number of plots.

col

if col is non-null it is assumed to contain colors to be used to colour the bodies of the box plots. By default they are in the background colour.

log

character indicating if x or y or both coordinates should be plotted in log scale.

pars

a list of (potentially many) more graphical parameters.

horizontal

logical indicating if the boxplots should be horizontal; default FALSE means vertical boxes.

add

logical, if TRUE add boxplot to current plot.

at

numeric vector giving the locations where the boxplots should be drawn; defaults to 1:n where n is the number of boxes.

...

other arguments (see boxplot).

Value

List with the following components:

stats

a matrix, each column contains the extreme of the lower whisker, the lower hinge, the midpoint, the upper hinge and the extreme of the upper whisker for one group/plot.

n

a vector with the number of observations in each group.

out

the values of any data points which lie beyond the extremes of the whiskers.

group

a vector of the same length as out whose elements indicate to which group the outlier belongs.

names

a vector of names for the groups.

Examples

#Example 1
data = data.frame(a=runif(10), b=runif(10), c=runif(10))
qboxplot(data, range=1.3, probs=c(0.2,0.5,0.7), qtype=6)

#Example 2
qboxplot(count~spray, data=InsectSprays, col="lightgray")

#Example 3
rb = qboxplot(decrease~treatment, data=OrchardSprays, log="y", col="bisque")
title("")
rb

#Example 4
mat = cbind(Uni05=(1:100)/21, Norm=rnorm(100), "5T"=rt(100,df=5),
            Gam2=rgamma(100,shape=2))
qboxplot(as.data.frame(mat))

#Example 5
data = c(102,133,136,139,142,144,146,151,160,174)
qboxplot(data.frame(data), range=1.5, probs=c(0.25,0.5,0.75), qtype=1,
         ylim=c(100,220), horizontal=TRUE)

Helper Function For qboxplot

Description

Produce quantile-based box-and-whisker plot(s) of the given (grouped) values.

Usage

qboxplot.stats(x, probs, qtype, range, output="all")

Arguments

x

a numeric vector of data values from which to calculate the requested statistics.

probs

numeric vector of values in [0,1] specifying the percentiles of the upper hinge, the midpoint (usually the median) and the lower hinge.

qtype

an integer between 1 and 9 indicating which one of the nine quantile algorithms to use (see quantile).

output

limit the output to "quantiles", "outliers" or "n" (see below), or, if set to "all" (the default), outputs a list containing all three.

range

this determines how far the plot whiskers extend out from the box. If range is positive, the whiskers extend to the most extreme data point which is no more than range times the difference in the value of the upper hinge and the value of the lower hinge from the box. A value of zero causes the whiskers to extend to the data extremes.

Value

List with the following components:

quantiles

a matrix, each column contains the extreme of the lower whisker, the lower hinge, the median, the upper hinge and the extreme of the upper whisker for one group/plot.

outliers

a vector with the number of observations in each group.

n

the values of any data points which lie beyond the extremes of the whiskers.

Examples

x = runif(100)
stats = qboxplot.stats(x, probs=c(0.4,0.5,0.6), qtype=7, range=1.5)
stats