sectioned.density {denstrip}R Documentation

Sectioned density plots


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.


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, ...)



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


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


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).


Number of fixed-width intervals for categorising the density.


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


Offset for adjacent rectangles. Defaults to width/3.


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.


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


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).


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


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".


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


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


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".


Christopher Jackson <> (R implementation)


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


## 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,
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)

[Package denstrip version 1.5.4 Index]