| densityPlot {openintro} | R Documentation | 
Density plot
Description
Compute kernel density plots, written in the same structure as
boxPlot. Histograms can be automatically added for teaching
purposes.
Usage
densityPlot(
  x,
  fact = NULL,
  bw = "nrd0",
  histo = c("none", "faded", "hollow"),
  breaks = "Sturges",
  fading = "0E",
  fadingBorder = "25",
  lty = NULL,
  lwd = 1,
  col = c("black", "red", "blue"),
  key = NULL,
  add = FALSE,
  adjust = 1,
  kernel = c("gaussian", "epanechnikov", "rectangular", "triangular", "biweight",
    "cosine", "optcosine"),
  weights = NULL,
  n = 512,
  from,
  to,
  na.rm = FALSE,
  xlim = NULL,
  ylim = NULL,
  main = "",
  ...
)
Arguments
| x | A numerical vector. | 
| fact | A character or factor vector defining the grouping for data in
 | 
| bw | Bandwidth. See  | 
| histo | Whether to plot a faded histogram ( | 
| breaks | The  | 
| fading | Character value of hexadecimal, e.g.  | 
| fadingBorder | Character value of hexadecimal, e.g.  | 
| lty | Numerical vector describing the line type for the density
curve(s). Each element corresponds to a different level of the
argument | 
| lwd | Numerical vector describing the line width for the density
curve(s). Each element corresponds to a different level of the
argument | 
| col | Numerical vector describing the line color for the density
curve(s). Each element corresponds to a different level of the
argument | 
| key | An argument to specify ordering of the factor levels. | 
| add | If  | 
| adjust | Argument passed to  | 
| kernel | Argument passed to  | 
| weights | Argument passed to  | 
| n | Argument passed to  | 
| from | Argument passed to  | 
| to | Argument passed to  | 
| na.rm | Argument passed to  | 
| xlim | x-axis limits. | 
| ylim | y-axis limits. | 
| main | Title for the plot. | 
| ... | If  | 
Author(s)
David Diez
See Also
Examples
# hollow histograms
histPlot(tips$tip[tips$day == "Tuesday"],
  hollow = TRUE, xlim = c(0, 30),
  lty = 1, main = "Tips by day"
)
histPlot(tips$tip[tips$day == "Friday"],
  hollow = TRUE, border = "red",
  add = TRUE, main = "Tips by day"
)
legend("topright",
  col = c("black", "red"),
  lty = 1:2, legend = c("Tuesday", "Friday")
)
# density plots
densityPlot(tips$tip, tips$day,
  col = c("black", "red"), main = "Tips by day"
)
legend("topright",
  col = c("black", "red"),
  lty = 1:2, legend = c("Tuesday", "Friday")
)
densityPlot(tips$tip,
  histo = "faded",
  breaks = 15, main = "Tips by day"
)
densityPlot(tips$tip,
  histo = "hollow",
  breaks = 30, fadingBorder = "66",
  lty = 1, main = "Tips by day"
)