Learn R Programming

rgr (version 1.0.4)

gx.hist: Plot a Histogram

Description

Plots a histogram for a data set, the user has options for defining the axis and main titles, the x-axis limits, arithmetic or logarithmic x-axis scaling, the number of bins the data are displayed in, and the colour of the infill.

Usage

gx.hist(xx, xlab = deparse(substitute(xx)), 
	ylab = "Number of Observations", log = FALSE, xlim = NULL, 
	main = " ", nclass = "Scott", colr = 8, ifnright = TRUE)

Arguments

xx
name of the variable to be plotted
xlab
a title for the x-axis. It is often desirable to replace the default x-axis title of the input variable name text string with a more informative title, e.g., xlab = "Cu (mg/kg) in <2 mm="" o-horizon="" soil"<="" code="">.
ylab
a default y-axis title of "Number of Observations" is provided, this may be changed, e.g., ylab = "Counts".
log
if it is required to display the data with logarithmic (x-axis) scaling, set log = TRUE.
xlim
default limits of the x-axis are determined in the function for use in other panel plots of function shape. However when used stand-alone the limits may be user-defined by setting xlim, see Note below.
main
when used stand-alone a title may be added optionally above the plot by setting main, e.g., main = "Kola Project, 1995".
nclass
the default procedure for preparing the histogram is to use the Scott (1979) rule. This usually provides an informative histogram, other optional rules are nclass = "Sturges" or nclass = "FD"; the later standing for Freedman-Diac
colr
by default the histogram is infilled in grey, colr = 8. If no infill is required, set colr = 0. See function display.lty for the range of available colours.
ifnright
controls where the sample size is plotted in the histogram display, by default this in the upper right corner of the plot. If the data distribution is such that the upper left corner would be preferable, set ifnright = FALSE.

Value

  • xlimA two element vector containing the actual minimum [1] and maximum [2] x-axis limits used in the histogram display are returned. These are use in function shape to ensure all panels have the same x-axis limits.

References

Venables, W.N. and Ripley, B.D., 2001. Modern Applied Statistics with S-Plus, 3rd Edition, Springer - see pp. 119 for a description of histogram bin selection computations.

See Also

display.lty, ltdl.fix.df, remove.na

Examples

Run this code
## Make test data available
data(kola.o) 
attach(kola.o)

## Generates an initial display to have a first look at the data and
## decide how best to proceed
gx.hist(Cu)

## Provides a more appropriate initial display
gx.hist(Cu, xlab = "Cu (mg/kg) in <2 mm O-horizon soil", log = TRUE)

## Causes the Friedman-Diaconis rule to be used to select the number 
## of histogram bins
shape(Cu, xlab = "Cu (mg/kg) in <2 mm O-horizon soil", log = TRUE, 
	nclass = "fd")

## Detach test data
detach(kola.o)

Run the code above in your browser using DataLab