The formula must be of the form ~quantitative
, quantitative~1
, quantitative~factor
, or quantitative~factor*factor2
where quantitative
is the quantitative variable to construct the histograms for and factor
or factor2
are factor variables that contain the levels for which separate histograms should be constructed.
If the formula is of the form ~quantitative
or quantitative~1
then only a single histogram of the quantitative variable will be produced. This allows hist.formula()
to be used similarly to hist()
but with a data=
argument.
The function produces a single (but see below) 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 nrow=
and ncol=
arguments. If the product of the number of rows and number of columns set by the user is less than the total number of histograms to be constructed then multiple pages of histograms will be produced (each requiring the user to click on the graph to go to the next graph). 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.
The default for right=
is not the same as that used in hist()
from graphics. Thus, right-open (left-closed) bins are the default.
The iaxs=
argument defaults to TRUE
so that xaxs="i"
and yaxs="i"
are used for both axes, which eliminates the “floating” x-axis that R typically plots for histograms.