color.density(x, col.nrm="darkblue", col.gen="blue", col.bg="seashell",
col.grid="grey90", col.hist="grey86",
col.fill.nrm=rgb(80,150,200, alpha=70, max=255),
col.fill.gen=rgb(250,210,230, alpha=70, max=255),
type=c("both", "general", "normal"),
xlab=NULL, main=NULL, ...)
"transparent"
.plot
, including xlim
, ylim
, lwd
and cex.lab
, col.main
, density
, dnorm
function and density
R functions for estimating densities from data, as well as the hist
function for calculating a histogram. Colors are provided by default and can also be specified.By default, the histogram is displayed in a light gray, as a background for the normal and/or general estimated density curves, though this color can be changed. Using the alpha
option for the rgb
function, the density curves are by default plotted with transparent colors to facilitate comparison to the background histogram.
No user-supplied values are passed to the hist
function itself, so only default values are permitted, such as the default bins as calculated by the default for the hist
function. Use the color.hist
function in this package for control over the parameters of the histogram.
The limits for the axes are automatically calculated so as to provide sufficient space for the density curves and histogram, and should generally not require user intervention. Also, the curves are centered over the plot window so that the resulting density curves are symmetric even if the underlying histogram is not. The estimated normal curve is based on the corresponding sample mean and standard deviation.
dnorm
, density
, hist
, plot
, rgb
.# generate 100 random normal data values
y <- rnorm(100)
# normal curve and general density curves superimposed over histogram
# all defaults
color.density(y)
# suppress the histogram, leaving only the density curves
# specify x-axis label per the xlab option for the plot function
color.density(y, col.hist="transparent", xlab="My Var")
# specify (non-transparent) colors for the curves,
# to make transparent, need alpha option for the rgb function
color.density(y, col.fill.nrm="darkgreen", col.fill.gen="plum")
# display only the general estimated density
# so do not display the estimated normal curve
# specify the bandwidth for the general density curve,
# use the standard bw option for the density function
color.density(y, type="general", bw=.6)
Run the code above in your browser using DataLab