density_histogram: Density histogram

Description Usage Arguments Value Examples

View source: R/utilities.R

Description

Construct a density histogram (i.e. probability = TRUE) as an xy-list in a form suitable for superimposing on other graphics, e.g. density plots. NOTE: this is NOT a plotting function. Use hist(x, probability = TRUE) for direct plots.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
density_histogram(x, ..., polygon = TRUE, plot)

## S3 method for class 'density_histogram'
print(
  x,
  ...,
  xlab = deparse(x$call$x),
  ylab = "Density",
  fill = alpha("sky blue", 0.5),
  colour = alpha("steel blue", 0.5)
)

Arguments

x, ...

As for hist, or an object of class "density_histogram" for the print method.

polygon

logical: suitable for use with polygon() rather than lines()?

plot

Ignored. Plotting is always suppressed

Value

A list with components including x and y suitable for superimposing on other graphics with lines()

Examples

1
2
3
4
5
6
7
d <- density(~log(crim), MASS::Boston)
h <- density_histogram(~log(crim), MASS::Boston, binWidth(1/3))
plot(d, xlim = xrange(d, h), ylim = yrange(d, h),
     main = "", xlab = "log(crim)", col = "blue")
lines(update(h, polygon = FALSE), col = alpha("red", 0.5))
polygon(h, fill = alpha("red", 0.5),
        colour = "transparent")

BillVenables/WWRGraphics documentation built on Feb. 1, 2021, 12:13 p.m.