Data Science – Examine Data Spread using Histogram and Density Plot

This article represents code samples in R programming language which could be used to draw histogram and density plot. Note that these plots are very useful for examining the data spread. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos.
Code Sample – Draw Histogram and Density Plot

Histrogram and density plot are very useful for examining the spread of a data variable. Following R commands with ggplot package helps in drawing histogram and density plots. As I am explaining with ggplot package, I am using diamonds data which comes with ggplot package. Pay attention to some of the following:

  • Draw Histogram: Command “ggplot(data) + geom_histogram(aes(x=variableName))” is used to draw the histogram. One could also provide binwidth as an additional parameter to geom_histogram function
  • Draw Density Plot: Command “ggplot(data) + geom_density(aes(x=variableName))” is used to create the density plot.
# Histogram to evaluate the spread of carat data
ggplot(diamonds) + geom_histogram(aes(x=carat))

# Density plot to evaluate the spread of carat data
ggplot(data=diamonds) + geom_density(aes(x=carat))
Ajitesh Kumar
Follow me

Ajitesh Kumar

I have been recently working in the area of Data Science and Machine Learning / Deep Learning. In addition, I am also passionate about various different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia etc and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data etc. I would love to connect with you on Linkedin.
Posted in Big Data. Tagged with , .

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.