Learn R Programming

sfsmisc (version 1.1-19)

histBxp: Plot a Histogram and a Boxplot

Description

Creates a histogram and a horizontal boxplot on the current graphics device.

Usage

histBxp(x, nclass, breaks, probability=FALSE, include.lowest=TRUE,
         xlab = deparse(substitute(x)),
         ...,
         width=0.2, boxcol=3, medcol=2, medlwd=5, whisklty=2, staplelty=1)

Arguments

x

numeric vector of data for histogram. Missing values (NAs) are allowed.

nclass

recommendation for the number of classes (i.e., bars) the histogram should have. The default is a number proportional to the logarithm of the length of x.

breaks

vector of the break points for the bars of the histogram. The count in the i-th bar is sum(breaks[i] < x <= breaks[i+1]) except that if include.lowest is TRUE (the default), the first bar also includes points equal to breaks[1]. If omitted, evenly-spaced break points are determined from nclass and the extremes of the data.

probability

logical flag: if TRUE, the histogram will be scaled as a probability density; the sum of the bar heights times bar widths will equal 1. If FALSE, the heights of the bars will be counts.

include.lowest

If TRUE (the default), the lowest bar will include data points equal to the lowest break, otherwise it will act like the other bars (see the description of the breaks argument).

xlab

character or expression for x axis labeling.

...

additional arguments to barplot. The hist function uses the function barplot to do the actual plotting; consequently, arguments to the barplot function that control shading, etc., can also be given to hist. See the barplot documentation for arguments angle, density, col, and inside. Do not use the space or histo arguments.

width

width of the box relative to the height of the histogram. DEFAULT is 0.2.

boxcol

color of filled box. The default is 3.

medcol

the color of the median line. The special value, NA, indicates the current plotting color (par("col")). The default is 2. If boxcol=0 and medcol is not explicitly specified this is set to the current plotting color (par("col")).

medlwd

median line width. The special value NA, is used to indicate the current line width (par("lwd")). The default is 5.

whisklty

whisker line type. The special value NA indicates the current line type (par("lty")). The default is 2 (dotted line).

staplelty

staple (whisker end cap) line type. The special value NA indicates the current line type (par("lty")). The default is 1 (solid line).

Graphical parameters (see par) may also be supplied as arguments to this function. In addition, the high-level graphics arguments described under par and the arguments to title may be supplied to this function.

Author

S-Plus: Markus Keller, Christian Keller; port to R in 1990's: Martin Mächler.

Details

If include.lowest is FALSE the bottom breakpoint must be strictly less than the minimum of the data, otherwise (the default) it must be less than or equal to the minimum of the data. The top breakpoint must be greater than or equal to the maximum of the data.

This function has been called hist.bxp() for 17 years; in 2012, the increasingly strong CRAN policies required a new name (which could not be confused with an S3 method name).

See Also

hist, barplot, boxplot, rug and scat1d in the Hmisc package.

Examples

Run this code
 lab <- "50 samples from a t distribution with 5 d.f."
 mult.fig(2*3, main = "Hist() + Rug()   and    histBxp(*)")
 for(i in 1:3) {
   my.sample <-  rt(50, 5)
   hist(my.sample, main=lab); rug(my.sample)# for 50 obs., this is ok, too..
   histBxp(my.sample, main=lab)
 }

Run the code above in your browser using DataLab