# 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