addhist: Add a Marginal Histogram

Description Usage Arguments See Also Examples

View source: R/addhist.R

Description

Add a marginal histogram to a plot.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
addhist(
  x,
  y = NULL,
  type = "xy",
  nclass = 20,
  newmar = 0:1,
  adj.fac = 1.05,
  xlab = "Frequency",
  ylab = "",
  fill = "gray"
)

Arguments

x

A numeric vector, the first set of data to be binned into a histogram.

y

A numeric vector, the second set of data to be binned into a histogram, default NULL.

type

A character scalar, indicating to which plot axes histograms should be added; "x" adds a histogram along the x-axis, "y" adds a histogram along the y-axis, "xy" (the default) adds a histogram along both axes.

nclass

An integer scalar, the target number of bins for the histogram, default 20.

newmar

A numeric vector of length 2, indicating new margins to use, default c(0, 1).

adj.fac

A numeric scalar, adjustment factor for extent of y-axis, default 1.05 (to ensure tallest bars in histogram are below axis box).

xlab

A character scalar, label for x-axis, default "Frequency".

ylab

A character scalar, label for y-axis, default "".

fill

A character or numeric scalar, color for filling in histogram bars, default "gray".

See Also

hist.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# fake data
xx <- rnorm(30)
yy <- runif(30)

# type "x"
layout(matrix(2:1, ncol=1), heights=c(1/5, 4/5))
par(mar=c(4, 4, 0, 1), cex=1, las=1)
plot(xx, yy)
addhist(xx, type="x")

# type "y"
layout(matrix(1:2, ncol=2), widths=c(4/5, 1/5))
par(mar=c(4, 4, 1, 0), cex=1, las=1)
plot(xx, yy)
addhist(yy, type="y")

# type "xy"
layout(matrix(c(2, 1, 0, 3), ncol=2),
 heights=c(1/5, 4/5), widths=c(4/5, 1/5))
par(mar=c(4, 4, 0, 0), cex=1, las=1)
plot(xx, yy)
usr <- par("usr")
mar <- par("mar")
addhist(xx, yy, type="xy")

JVAdams/jvamisc documentation built on Aug. 11, 2021, 6:43 a.m.