hist.formula {NCStats}R Documentation

Creates separate histograms by levels.

Description

Creates separate histograms of a quantitative variable by levels of a factor variable.

Usage

## S3 method for class 'formula':
hist(formula,data=NULL,xlab=names(DF)[1],breaks="Sturges",
            same.breaks=TRUE,same.ylim=TRUE,ylmts=NULL,
            main.pre=paste(names(DF)[[2]],"==",sep=""),
            rows=round(sqrt(num)),cols=ceiling(sqrt(num)),...)

Arguments

formula A formula of class(formula). See details.
data An optional data frame containing the variables in the model.
xlab A character label for the x-axis. Defaults to name of quantitative variable in the formula.
breaks Same type of arguments as in hist.
same.breaks A logical indicating whether the same break positions should be used on each histogram. Defaults to TRUE.
same.ylim A logicial indicating whether the same limits for the y-axis should be used on each histogram. Defaults to TRUE. Ignored if ylmts is non-null.
ylmts A single value that sets the maximum y-axis limit for each histogram or a vector of length equal to the number of groups that sets the maximum y-axis limit for each histogram separately.
main.pre A character string to be used as a prefix for the main title. See details.
rows A numeric containing the number of rows to use on the graphic.
cols A numeric containing the number of columns to use on the graphic.
... Other arguments to pass through to the hist function.

Details

The formula must be of the form quantitative~factor where quantitative is the quantitative variable to construct the histograms for and factor is a factor variable containing the levels for which separate histograms should be constructed.

The function produces a single graphic that consists of a grid on which the separate histograms are printed. The rows and columns of this grid are determined to construct a plot that is as square as possible. However, the rows and columns can be set by the user with the rows= and cols= arguments. The x-axis of each separate histogram will be labeled identically. The default x-axis label is the name of the quantitative variable. This can be changed by the user with the xlab= argument. Each histogram is also labeled with a main title that consists of the string in the main.pre= argument and the name of the level in the factor variable. The default prefix is to list the name of the factor variable and the “==”. If the user wants the main title to be just the name of the factor level then set main=NULL.

Value

Nothing is returned; however, a graphic is produced.

Author(s)

Derek H. Ogle, dogle@northland.edu; largely a modification of the code provided by Marc Schwartz on the R-help mailing list on 1Jun07.

See Also

hist, multhist in plotrix.

Examples

data(iris)
hist(Sepal.Length~Species,data=iris)
hist(Sepal.Length~Species,xlab="Sepal Length (cm)",data=iris)
hist(Sepal.Length~Species,xlab="Sepal Length (cm)",main.pre=NULL,data=iris)
hist(Sepal.Length~Species,xlab="Sepal Length (cm)",same.breaks=FALSE,same.ylim=FALSE,data=iris)
hist(Sepal.Length~Species,xlab="Sepal Length (cm)",rows=1,cols=3,data=iris)

[Package NCStats version 0.0-12 Index]