histbackback

0th

Percentile

Back to Back Histograms

Takes two vectors or a list with x and y components, and produces back to back histograms of the two datasets.

Keywords
hplot, distribution, dplot
Usage
histbackback(x, y, brks=NULL, xlab=NULL, axes=TRUE, probability=FALSE, xlim=NULL, ylab='', ...)
Arguments
x,y
either two vectors or a list given as x with two components. If the components have names, they will be used to label the axis (modification FEH).
brks
vector of the desired breakpoints for the histograms.
xlab
a vector of two character strings naming the two datasets.
axes
logical flag stating whether or not to label the axes.
probability
logical flag: if TRUE, then the x-axis corresponds to the units for a density. If FALSE, then the units are counts.
xlim
x-axis limits. First value must be negative, as the left histogram is placed at negative x-values. Second value must be positive, for the right histogram. To make the limits symmetric, use e.g. ylim=c(-20,20).
ylab
label for y-axis. Default is no label.
...
additional graphics parameters may be given.
Value

a list is returned invisibly with the following components:

Side Effects

a plot is produced on the current graphics device.

See Also

hist, histogram

Aliases
  • histbackback
Examples
options(digits=3)
set.seed(1)
histbackback(rnorm(20), rnorm(30))


fool <- list(x=rnorm(40), y=rnorm(40))
histbackback(fool)
age <- rnorm(1000,50,10)
sex <- sample(c('female','male'),1000,TRUE)
histbackback(split(age, sex))
agef <- age[sex=='female']; agem <- age[sex=='male']
histbackback(list(Female=agef,Male=agem), probability=TRUE, xlim=c(-.06,.06))
Documentation reproduced from package Hmisc, version 4.0-2, License: GPL (>= 2)

Community examples

michael.menke@gmail.com at Jul 6, 2017 Hmisc v4.0-3

par(new=FALSE) out <- histbackback(split(wright.dat$data, wright.dat$kind), probability=TRUE, xlim=c(-.90, 2.5), main="Wright Map, Raw Data\n sides reversed") barplot(-out$left, col="orange" , horiz=TRUE, space=0, add=TRUE, axes=FALSE) barplot(out$right, col="purple", horiz=TRUE, space=0, add=TRUE, axes=FALSE) par(new=FALSE) out <- histbackback(split(wright.dat$data, wright.dat$kind), probability=TRUE, xlim=c(-.90, 2.5), main="Wright Map, Raw Data\n sides reversed") barplot(-out$left, col="orange" , horiz=TRUE, space=1, add=TRUE, axes=FALSE) barplot(out$right, col="purple", horiz=TRUE, space=1, add=TRUE, axes=FALSE) par(new=FALSE) out <- histbackback(list(item.wright$data, prev.wright$data), probability=TRUE, xlim=c(-1, 1), main="Wright Map, Raw Data\n sides reversed?") barplot(out$left, col="orange" , horiz=TRUE, space=0, add=TRUE, axes=FALSE) barplot(-out$right, col="purple", horiz=TRUE, space=0, add=TRUE, axes=FALSE) par(new=FALSE) out <- histbackback(list(prev.wright$data, item.wright$data), probability=TRUE, xlim=c(-3, 1), xlab="", main="Wright Map, Raw Data sides correct \n needs standard scores: jmenke@atsu.edu") barplot(-out$left, col="orange", horiz=TRUE, space=0, add=TRUE, axes=FALSE, ylab="") barplot(out$right, col="purple", horiz=TRUE, space=0, add=TRUE, axes=FALSE, xlab="") par(new=FALSE) out <- histbackback(list(prev.wright$data, item.wright$data), probability=TRUE, xlim=c(-3, 1), xlab="", main="Wright Map, Raw Data sides correct \n needs standard scores: jmenke@atsu.edu") barplot(-out$left, col="orange", horiz=TRUE, space=0, add=TRUE, axes=FALSE, ylab="") barplot(out$right, col="purple", horiz=TRUE, space=0, add=TRUE, axes=FALSE, xlab="")