Create Demo dataset to be used for a plot.
set.seed(007)
x <- c(rnorm(300, mean=55, sd=5.5),
rnorm(300, mean=65, sd=6.5))
head(x)
## [1] 67.57986 48.41776 51.18139 52.73239 49.66130 49.78996
hist(x, breaks = "Sturges")
hist(x, col = "steelblue")
# Change the number of breaks
hist(x, col = "steelblue", breaks = 60)
# Compute the density data
dens <- density(mtcars$mpg)
# plot density
plot(dens, frame = FALSE, col = "steelblue",
main = "Density plot of mpg")
# Fill the density plot using polygon()
plot(dens, frame = FALSE, col = "steelblue", main = "Density plot of mpg")
polygon(dens, col = "steelblue")