{"id":280,"date":"2015-08-10T20:10:34","date_gmt":"2015-08-10T19:10:34","guid":{"rendered":"http:\/\/pzd.hmy.temporary.site\/?p=280"},"modified":"2017-10-30T15:35:43","modified_gmt":"2017-10-30T19:35:43","slug":"histogram-with-r","status":"publish","type":"post","link":"https:\/\/datascienceplus.com\/histogram-with-r\/","title":{"rendered":"How to make Histogram with R"},"content":{"rendered":"<p>Histogram are frequently used in data analyses for visualizing the data. Through histogram, we can identify the distribution and frequency of the data. Histogram divide the continues variable into groups (x-axis) and gives the frequency (y-axis) in each group. The function that histogram use is <code>hist()<\/code>. Below I will show a set of examples by using a <code>iris<\/code> dataset which comes with R.<\/p>\n<p>Basic histogram:<\/p>\n<pre>\r\nhist(iris$Petal.Length)\r\n<\/pre>\n<p>Here is the basic histogram:<br \/>\n<a href=\"https:\/\/datascienceplus.com\/wp-content\/uploads\/2015\/08\/Plot-basic-histogram.png\"><img decoding=\"async\" src=\"https:\/\/datascienceplus.com\/wp-content\/uploads\/2015\/08\/Plot-basic-histogram.png\" alt=\"Plot-basic-histogram\" class=\"image-inpost\" \/><\/a><\/p>\n<p>Adding color and labels in histograms:<\/p>\n<pre>\r\nhist(iris$Petal.Length, col=\"blue\", xlab=\"Petal Length\", main=\"Colored histogram\")\r\n<\/pre>\n<p>Histogram with labels:<br \/>\n<a href=\"https:\/\/datascienceplus.com\/wp-content\/uploads\/2015\/08\/Rplot-color-histogram.png\"><img decoding=\"async\" src=\"https:\/\/datascienceplus.com\/wp-content\/uploads\/2015\/08\/Rplot-color-histogram.png\" alt=\"Rplot-color-histogram\" class=\"image-inpost\" \/><\/a><\/p>\n<p>Adding breaks in histograms to give more information about the distribution:<\/p>\n<pre>\r\nhist(iris$Petal.Length, breaks=30, col=\"gray\", xlab=\"Petal Length\", main=\"Colored histogram\")\r\n<\/pre>\n<p>Histogram with more bars:<br \/>\n<a href=\"https:\/\/datascienceplus.com\/wp-content\/uploads\/2015\/08\/Rplot-breaks-histogram.png\"><img decoding=\"async\" src=\"https:\/\/datascienceplus.com\/wp-content\/uploads\/2015\/08\/Rplot-breaks-histogram.png\" alt=\"Rplot-breaks-histogram\" class=\"image-inpost\" \/><\/a><\/p>\n<p>In statistics, the histogram is used to evaluate the distribution of the data. In order to show the distribution of the data we first will show density (or probably) instead of frequency, by using function <code>freq=FALSE<\/code>. Secondly, we will use the function <code>curve()<\/code> to show normal distribution line.<\/p>\n<p>Here the example:<\/p>\n<pre>\r\n# add a normal distribution line in histogram\r\nhist(iris$Petal.Length, freq=FALSE, col=\"gray\", xlab=\"Petal Length\", main=\"Colored histogram\")\r\ncurve(dnorm(x, mean=mean(iris$Petal.Length), sd=sd(iris$Petal.Length)), add=TRUE, col=\"red\") #line\r\n<\/pre>\n<p>Histogram with normal distribution line:<br \/>\n<a href=\"https:\/\/datascienceplus.com\/wp-content\/uploads\/2015\/08\/Rplot-normal-distribution-histogram.png\"><img decoding=\"async\" src=\"https:\/\/datascienceplus.com\/wp-content\/uploads\/2015\/08\/Rplot-normal-distribution-histogram.png\" alt=\"Rplot-normal-distribution-histogram\" class=\"image-inpost\" \/><\/a><\/p>\n<p>That&#8217;s all about histogram in this post if you have any question leave a comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Histogram are frequently used in data analyses for visualizing the data. Through histogram, we can identify the distribution and frequency of the data. Histogram divide the continues variable into groups (x-axis) and gives the frequency (y-axis) in each group. The function that histogram use is hist(). Below I will show a set of examples by [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":285,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[232],"class_list":["post-280","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visualizing-data","tag-rstats"],"views":67045,"_links":{"self":[{"href":"https:\/\/datascienceplus.com\/wp-json\/wp\/v2\/posts\/280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/datascienceplus.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/datascienceplus.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/datascienceplus.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/datascienceplus.com\/wp-json\/wp\/v2\/comments?post=280"}],"version-history":[{"count":0,"href":"https:\/\/datascienceplus.com\/wp-json\/wp\/v2\/posts\/280\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/datascienceplus.com\/wp-json\/wp\/v2\/media\/285"}],"wp:attachment":[{"href":"https:\/\/datascienceplus.com\/wp-json\/wp\/v2\/media?parent=280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/datascienceplus.com\/wp-json\/wp\/v2\/categories?post=280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/datascienceplus.com\/wp-json\/wp\/v2\/tags?post=280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}