This help topic is for R version 0.60. For the current version of R, try https://stat.ethz.ch/R-manual/R-patched/library/base/html/hist.html
hist {base}R Documentation

Histograms

Description

hist computes and plots a histogram of the given data values. The histogram cells are intervals of the form [a,b), i.e. they include their left-hand endpoint, but not their right one.

Usage

hist(x, breaks, freq = NULL, col = NULL, border = par("fg"),
     main = paste("Histogram of" , deparse(substitute(x))),
     xlim = range(breaks),  ylim = range(counts, 0),
     xlab = deparse(substitute(x)),  ylab,
     axes = TRUE, plot = TRUE, ...)

Arguments

x

a vector of values for which the histogram is desired.

breaks

either a single number giving the approximate number of cells for the histogram or a vector giving the breakpoints between histogram cells.

freq

a logical vector indicating whether the histogram is to present a representation of frequencies (the default if breaks are equidistant) or relative frequencies (“probabilities”).

col

a colour to be used to fill the bars. The default of NULL yields unfilled bars.

border

the color of the border around the bars.

main, xlab, ylab

these arguments to title have useful defaults here.

xlim, ylim

the range of x and y values with sensible defaults.

plot

logical. If TRUE (default), a histogram is plotted, otherwise a list of breaks and counts is returned.

...

further graphical parameters to title and axis.

Value

a list with components

breaks

the n+1 cell boundaries (= breaks if that was a vector).

counts

n integers; for each cell, the number of x[] inside.

rel.freqs

the relative frequencies

mids

the n cell midpoints; useful for plotting.

Examples

data(islands)
op <- par(mfrow=c(2,2))
hist(islands)
r <- hist(islands, col="gray")
text(r$mids,r$counts,r$counts,adj=c(.5,-.5))

hist(sqrt(islands), br = 12, col="lightblue", border="pink")
##-- For non-equidistant breaks, counts should NOT be graphed unscaled:
r <- hist(sqrt(islands), br = c(4* 0:5,10* 3:5,70,100,140), col='blue1')
text(r$mids, r$rel.fr, r$counts, adj=c(.5,-.5), col='blue3')
par(op)

str(hist(islands, plot= F))
str(hist(islands, br=12, plot= F))

[Package base version 0.60 ]