Produce box-and-whisker plot(s) of the given (grouped, weighted) values.
wtd.boxplot(x, …)# S3 method for formula
wtd.boxplot(formula, weights = NULL, data = NULL, …, subset, na.action = NULL)
# S3 method for default
wtd.boxplot(x, weights = NULL, …, range = 1.5, width = NULL, varwidth = FALSE,
notch = FALSE, outline = TRUE, names, 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)
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).
case weights, vector of the same length as the dependent variable in formula or the variable given as arguments)
a data.frame (or list) from which the variables in
formula
should be taken.
an optional vector specifying a subset of observations to be used for plotting.
a function which indicates what should happen
when the data contain NA
s. The default is to ignore missing
values in either the response or the group.
for specifying data from which the boxplots are to be
produced. Either a numeric vector, or a single list containing such
vectors. Additional unnamed arguments specify further data
as separate vectors (each corresponding to a component boxplot).
NA
s are allowed in the data.
For the formula
method, named arguments to be passed to
the default method.
For the default method, unnamed arguments are additional data
vectors (unless x
is a list when they are ignored),
and named arguments are arguments and graphical parameters to be
passed to bxp
in addition to the ones
given by argument pars
(and override those in pars
).
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 interquartile range from the box. A value
of zero causes the whiskers to extend to the data extremes.
a vector giving the relative widths of the boxes making up the plot.
if varwidth
is TRUE
, the boxes are
drawn with widths proportional to the square-roots of the number
of observations in the groups.
if notch
is TRUE
, a notch is drawn in
each side of the boxes. If the notches of two plots do not
overlap this is ‘strong evidence’ that the two medians differ
(Chambers et al., 1983, p. 62). See boxplot.stats
for the calculations used.
if outline
is not true, the outliers are
not drawn (as points whereas S+ uses lines).
group labels which will be printed under each boxplot. Can be a character vector or an expression (see plotmath).
a scale factor to be applied to all boxes. When there are only a few groups, the appearance of the plot can be improved by making the boxes narrower.
staple line width expansion, proportional to box width.
outlier line width expansion, proportional to box width.
if TRUE
(the default) then a boxplot is
produced. If not, the summaries which the boxplots are based on
are returned.
an optional vector of colors for the outlines of the
boxplots. The values in border
are recycled if the
length of border
is less than the number of plots.
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.
character indicating if x or y or both coordinates should be plotted in log scale.
a list of (potentially many) more graphical parameters,
e.g., boxwex
or outpch
; these are passed to
bxp
(if plot
is true); for details, see there.
logical indicating if the boxplots should be
horizontal; default FALSE
means vertical boxes.
logical, if true add boxplot to current plot.
numeric vector giving the locations where the boxplots should
be drawn, particularly when add = TRUE
;
defaults to 1:n
where n
is the number of boxes.
List with the following components:
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. If all the inputs have the same class attribute, so will this component.
a vector with the number of observations in each group.
a matrix where each column contains the lower and upper extremes of the notch.
the values of any data points which lie beyond the extremes of the whiskers.
a vector of the same length as out
whose elements
indicate to which group the outlier belongs.
a vector of names for the groups.
The generic function wtd.boxplot
currently has a default method
(wtd.boxplot.default
) and a formula interface (wtd.boxplot.formula
).
If multiple groups are supplied either as multiple arguments or via a
formula, parallel boxplots will be plotted, in the order of the
arguments or the order of the levels of the factor (see
factor
).
Missing values are ignored when forming boxplots.
# NOT RUN {
x<-1:10
fc<-rep(c("a","b"),each=5)
wt<-c(6:10,10:6)
wtd.boxplot(x~fc,weights=wt)
# }
Run the code above in your browser using DataLab