R Language Base Plotting Density plot


Example

A very useful and logical follow-up to histograms would be to plot the smoothed density function of a random variable. A basic plot produced by the command

plot(density(rnorm(100)),main="Normal density",xlab="x")

would look like

rnorm density plot example

You can overlay a histogram and a density curve with

x=rnorm(100)
hist(x,prob=TRUE,main="Normal density + histogram")
lines(density(x),lty="dotted",col="red")

which gives

Overlay rnorm