Hist: An Alternative Histogram Function

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/Hist.R

Description

Hist generates a histogram with better (IMNSHO) defaults than the hist() function.

Usage

1
2
3
4
5
6
7
8
9
Hist(
  x,
  breaks = "Sturges",
  ylog = F,
  xlab = NULL,
  ylab = "Counts",
  bound = T,
  ...
)

Arguments

x

Numeric vector of values to be histogramed.

breaks

one of:

  • a vector giving the breakpoints between histogram cells,

  • a function to compute the vector of breakpoints,

  • a single number giving the number of cells for the histogram,

  • a character string naming an algorithm to compute the number of cells (see ‘Details’),

  • a function to compute the number of cells.

In the last three cases the number is a suggestion only; as the breakpoints will be set to pretty values, the number is limited to 1e6 (with a warning if it was larger). If breaks is a function, the x vector is supplied to it as the only argument (and the number of breaks is only limited by the amount of available memory).

ylog

Logical or numeric, controlling whether y-axis is logged. If TRUE, log(counts+1, 10) is plotted; use integer to specify the base. Default is FALSE (linear y-axis).

xlab, ylab

Character values; labels for the x- and y-axes

bound

Logical value. If TRUE, values outside the range of breaks are added to the extreme bins; otherwise, they are excluded. Ignored if length(breaks)==1.

...

Other plotting arguments passed to barplot or axis as appropriate (see also plot.default).

Details

The behavior of Hist() is very similar to hist(), but with the following differences:

Value

Returns a histogram object, like what is returned by the hist function, but with additional elements:

Author(s)

M.W.Rowe, mwr.stats@gmail.com

See Also

plot.default, par, axis for more details about plotting options, as well as barplot and hist,

Examples

1
2
3
4
5
6
7
8
# plot normally distributed random numbers, with y-axis logged
this.hist <- Hist(rnorm(10000), 40, ylog=TRUE)
# vertical lines at +/-2
abline(v=this.hist$xbin(c(-2, 2)), col="red", lty=3, lwd=2)
# plot it again, without logging the y-axis
this.hist <- Hist(rnorm(10000), 40)
# for comparison, look at the standard histogram function
plot(this.hist)

mwrowe/microRutils documentation built on June 12, 2021, 2:41 p.m.