plot.histogram: Plots a histogram

Description Usage Arguments Author(s) See Also Examples

Description

This function redefines the plot.histogram function in the R base package by adding the two arguments width and offset. The function is modified in such a way that it is backward compatible, i.e. if you do not use the arguments width and offset the plot will look the same as the plot generated by the original function. Note that plot.histogram is called by hist.

Usage

1
2
3
4
5
## S3 method for class 'histogram'
plot(x, freq=equidist, density=NULL, angle=45, col=NULL, border=par("fg"), lty=NULL,
  main=paste("Histogram of", x$xname), sub=NULL, xlab=x$xname, ylab,
  xlim=range(x$breaks), ylim=NULL, axes=TRUE, labels=FALSE, add=FALSE, width=1,
  offset=(1 - width)/2, ...)

Arguments

x

a ‘histogram’ object, or a list with components intensities, mid, etc, see hist.

freq

logical; if TRUE, the histogram graphic is to present a representation of frequencies, i.e, x$counts; if FALSE, relative frequencies ("probabilities"), i.e., x$intensities, are plotted. The default is true for equidistant breaks and false otherwise.

density

the density of shading lines, in lines per inch. If NULL, no shading lines are drawn. Non-positive values also inhibit the drawing of shading lines.

angle

the slope of shading lines, given as an angle in degrees (counter-clockwise).

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.

width

The relative width of each bar compared to the full width. 1.0 is full width. Default value is 1.0.

offset

The relative horisontal offset of each bar compared to the full width. A value of 0.0 places each bar to the very left. A value of 1.0-width places each bar to the very right. Default value is (1.0-offset)/2, i.e. the bars are centered.

lty

the line type used for the bars, see also lines.

xlim, ylim

the range of x and y values with sensible defaults.

main, sub, xlab, ylab

these arguments to title have useful defaults here.

axes

logical, indicating if axes should be drawn.

labels

logical or character. Additionally draw labels on top of bars, if not FALSE; if TRUE, draw the counts or rounded intensities; if labels is a character, draw itself.

add

logical. If TRUE, only the bars are added to the current plot. This is what lines.histogram(*) does.

...

further graphical parameters to title and axis.

Author(s)

Modified by Henrik Bengtsson (http://www.braju.com/R/), from the original R plot.histogram.

See Also

See also original plot.histogram.

Examples

1
2
3
4
5
6
7
  x1 <- rnorm(1000,  0.4, 0.8)
  x2 <- rnorm(1000,  0.0, 1.0)
  x3 <- rnorm(1000, -1.0, 1.0)
  hist(x1, width=0.33, offset=0.00, col="blue", xlim=c(-4,4),
   main="Histogram of x1, x2 & x3", xlab="x1 - blue, x2 - red, x3 - green")
  hist(x2, width=0.33, offset=0.33, col="red", add=TRUE)
  hist(x3, width=0.33, offset=0.66, col="green", add=TRUE)

HenrikBengtsson/R.basic documentation built on May 6, 2019, 11:51 p.m.