Histograms

Sameer Mathur

Simple Histograms

hist(mtcars$mpg)

plot of chunk unnamed-chunk-1

Histogram with Specified Number of Bins

hist(mtcars$mpg, 
     breaks=12, 
     xlab="Miles Per Gallon", 
     main="Histogram with specified number of bins")

Histogram with 12 Number of Bins

plot of chunk unnamed-chunk-3

Kernel Density Curve

p <- plot(density(mtcars$mpg))
lines(p, col="black", lwd=2)

We can see the distribution of continuous variable using the kernel density plots.

Kernel Density Curve

plot of chunk unnamed-chunk-5

Histogram with Density Curve

hist(mtcars$mpg, 
     freq=FALSE, 
     breaks=12, 
     xlab="Miles Per Gallon", 
     main="Histogram with density curve")  
lines(density(mtcars$mpg), col="black", lwd=2)

Histogram with Density Curve

plot of chunk unnamed-chunk-7

Histogram with Rug Plot

hist(mtcars$mpg, 
     freq=FALSE, 
     breaks=12, 
     xlab="Miles Per Gallon", 
     main="Histogram with rug plot")  
rug(jitter(mtcars$mpg)) 

A rug plot is one dimensional representation of the actual data values. If there are many tied values, we can jitter the data on the rug plot.

Histogram with Rug Plot

plot of chunk unnamed-chunk-9