Learn R Programming

denstrip (version 1.5.4)

sectioned.density: Sectioned density plots

Description

Sectioned density plots (Cohen and Cohen, 2006) use shading and occlusion to give a compact illustration of a distribution, such as the empirical distribution of data.

Usage

sectioned.density(x, dens, at, width, offset, ny,
                  method=c("kernel","frequency"), nx, horiz=TRUE,
                  up.left = TRUE, colmax, colmin="white", gamma=1,
                  lattice=FALSE, …)
panel.sectioned.density(...)

Arguments

x

Either the vector of points at which the density is evaluated (if dens supplied), or a sample from the distribution (if dens not supplied).

dens

Density at points. If dens is not supplied, the density of the distribution underlying x is estimated using the method specified in method.

at

Position of the bottom of the plot on the y-axis (if horiz=TRUE) or position of the right of the plot on the x-axis (if horiz=FALSE) (required).

ny

Number of fixed-width intervals for categorising the density.

width

Width of individual rectangles in the plot. Defaults to the range of the axis divided by 20.

offset

Offset for adjacent rectangles. Defaults to width/3.

method

Method of estimating the density of x, when dens is not supplied.

If "kernel" (the default) then kernel density estimation is used, via density(x,…).

If "frequency" then the density is estimated as the relative frequency in a series of bins, as in Cohen and Cohen (2006). This method is controlled by the number of data bins nx.

nx

Number of data bins for the "frequency" density estimation method. The default uses Sturges' formula (see nclass.Sturges, hist).

horiz

If horiz=TRUE, then the plot is horizontal and points upwards. If horiz=FALSE then the plot is vertical and points leftwards, as the illustrations in Cohen and Cohen (2006).

up.left

If changed to FALSE, then horizontal plots point downwards and vertical plots point rightwards.

colmax

Darkest colour, either as a built-in R colour name (one of colors()) or an RGB hex value. Defaults to par("fg") or its lattice equivalent, which is normally "black", or "#000000".

colmin

Lightest colour, either as a built-in R colour name (one of colors()) or an RGB hex value. Defaults to white.

gamma

Gamma correction to apply to the colour palette, see denstrip.

lattice

Set this to TRUE to make sectioned.density a lattice panel function instead of a base graphics function. panel.sectioned.density(x,...) is equivalent to sectioned.density(x, lattice=TRUE, ...).

Additional arguments supplied to density(x,…), if method="kernel".

References

Cohen, D. J. and Cohen, J. The sectioned density plot. The American Statistician (2006) 60(2):167--174

Examples

Run this code
# NOT RUN {
## Fisher's iris data 
## Various settings to change the look of the plot
hist(iris$Sepal.Length, nclass=20, col="lightgray")
sectioned.density(iris$Sepal.Length, at=0.2)
sectioned.density(iris$Sepal.Length, at=5)
sectioned.density(iris$Sepal.Length, at=10, width=0.5)
hist(iris$Sepal.Length, nclass=20, col="lightgray")
sectioned.density(iris$Sepal.Length, at=7, width=0.5,
                  offset=0.1, colmax="darkmagenta")
sectioned.density(iris$Sepal.Length, at=9, width=0.5,
                  offset=0.1, ny=15, colmin="lemonchiffon")
## frequency method less smooth than kernel density 
sectioned.density(iris$Sepal.Length, at=12, width=0.5, offset=0.1,
                  method="frequency")
sectioned.density(iris$Sepal.Length, at=13.5, width=0.5, offset=0.1,
                  method="frequency", nx=20)

## Illustrate a known distribution
x <- seq(-4, 4, length=1000)
dens <- dnorm(x)
plot(x, xlim=c(-5, 5), ylim=c(-5, 5), xlab="x", ylab="x", type="n")
sectioned.density(x, dens, ny=8, at=0, width=0.3)
sectioned.density(x, dens, ny=16, at=2, width=0.1)
sectioned.density(x, dens, at=-3, horiz=FALSE)
sectioned.density(x, dens, at=4, width=0.3, horiz=FALSE)

# }

Run the code above in your browser using DataLab