Learn R Programming

berryFunctions (version 1.11.0)

classify: Classification into groups

Description

classify continuous values into categories with different methods: - linearly or logarithmically spaced equal intervals, - intervals based on quantiles (equally filled bins), - intervals based on distance from the mean in normal distributions, - user specified class borders (e.g. for legal or critical limits).

Usage

classify(x, method = "equalinterval", breaks, Range = range(x, finite = TRUE), sdlab = 1, quiet = FALSE)

Arguments

x
Vector with numeric values
method
Character string (partial matching is performed). Classification method or type of binning to compute the class breakpoints. See section Details. DEFAULT: "equalinterval")
breaks
Specification for method, see Details. DEFAULT: different defaults for each method
Range
Ends of color bar for method=equalinterval. DEFAULT: range(x, finite=TRUE)
sdlab
Type of label and breakpoints if method=standarddeviation. 1 means -0.5 sd, 0.5 sd, 2 means -1 sd, mean, 1 sd, 3 means actual numbers for type 1, 4 means numbers for type 2.
quiet
Suppress warnings, eg for values outside Range? DEFAULT: FALSE

Value

list with class numbers (index) and other elements for colPoints

Details

Binning methods are explained very nicely in the link in the section References. nbins indicates the number of classes (and thus, colors).

method | explanation | meaning of breaks
| default ---------- | -----------
| ----------- | ------- equalinterval
| nbins equally spaced classes | nbins | 100
quantile | classes have equal number of values | the quantiles (or number of them)
| 0:4/4 standarddeviation | normal distributions
| the number of sd in one direction from the mean | 3 logspaced
| nbins logarithmically spaced | c(nbins, base), see logSpaced | c(100,1.2)
usergiven | custom breakpoints | personal breakpoint values (including ends of Range)
| none method | explanation
The default is set to equalinterval which makes sense for my original intent of plotting lake depth (bathymetry measured at irregularly distributed points) on a linear color scale. This is the workhorse for colPoints.

References

See this page on the effect of classification (binning) methods: http://uxblog.idvsolutions.com/2011/10/telling-truth.html

See Also

colPoints

Examples

Run this code

classify( c(1:10, 20), breaks=12)
classify( c(1:10, 20), "q", breaks=0:10/10)
classify( c(1:10, 20), "s", sdlab=2 )
classify( c(1:10, 20), "s", sdlab=1, breaks=2 )
classify( c(1:10, 20), "u", breaks=c(5,27) )
classify( c(1:10, 20), "l")

Run the code above in your browser using DataLab