Learn R Programming

pedometrics (version 0.6-3)

plotHD: Histogram and density plot

Description

This function plots a histogram and a density plot of a single variable using the R-package lattice.

Usage

plotHD(x, HD = "over", nint = 20, digits = 2, stats = TRUE,
  BoxCox = FALSE, col = c("lightgray", "black"), lwd = c(1, 1),
  lty = "dashed", xlim, ylim, ...)

Arguments

x
Vector of numeric values of the variable for which the histogram nd density plot should be created.
HD
Character value indicating the type of plot to be created. Available options are "over", to create a histogram superimposed by the theoretical density plot of a normally distributed variable, and "stack", to create a histogram an
nint
Integer specifying the number of histogram bins. Defaults to nint = 20.
digits
Integer indicating the number of decimal places to be used when printing the statistics of the variable x. Defaults to digits = 2.
stats
Logical to indicate if descriptive statistics of the variable x should be added to the plot. Available only when HD = "over". The function tries to automatically find the best location to put the descriptive statistics given the
BoxCox
Logical to indicate if the variable x should be transformed using the Box-Cox family of power transformations. The estimated lambda value of the Box-Cox transform is printed in the console. It is set to zero when negative. Defaults to B
col
Vector of two elements, the first indicating the color of the histogram, the second indicating the color of the density plot. Defaults to col = c("lightgray", "black").
lwd
Vector of two elements, the first indicating the line width of the histogram, the second indicating the line width of the density plot. Defaults to lwd = c(1, 1).
lty
Character value indicating the line type for the density plot. Defaults to lty = "dashed".
xlim
Vector of two elements defining the limits of the x axis. The function automatically optimizes xlim based on the density plot.
ylim
Vector of two elements defining the limits of the y axis. The function automatically optimizes ylim based both histogram and density plot.
...
Other arguments that can be passed to lattice functions. There is no guarantee that they will work.

Value

  • An object of class "trellis". The update.trellis method can be used to update components of the object and the print.trellis print method (usually called by default) will plot it on an appropriate plotting device.

Details

The user should visit the help pages of histogram, densityplot, panel.mathdensity, powerTransform and bcPower to obtain more details about the main functions used to built plotHD.

References

Sarkar, Deepayan (2008) Lattice: Multivariate Data Visualization with R, Springer. http://lmdvr.r-forge.r-project.org/

See Also

histogram, densityplot, panel.mathdensity, powerTransform, bcPower.

Examples

Run this code
x <- rnorm(100, 10, 2)
plotHD(x, HD = "stack")
plotHD(x, HD = "over")

Run the code above in your browser using DataLab