{"id":78541,"date":"2020-05-05T16:34:05","date_gmt":"2020-05-05T11:04:05","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=78541"},"modified":"2020-05-05T16:34:05","modified_gmt":"2020-05-05T11:04:05","slug":"histogram-in-r","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/","title":{"rendered":"Histogram in R &#8211; Implementation and Customization"},"content":{"rendered":"<p>In this TechVidvan R Tutorial series, we will learn what is histogram in R, how to implement it. We will also look at how to plot them using the ggplot2 package. So, without any further ado, let\u2019s get started.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/Histograms-in-R.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78561\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/Histograms-in-R.jpg\" alt=\"Histogram in R\" width=\"802\" height=\"420\" \/><\/a><\/p>\n<h2>Histogram In R<\/h2>\n<p>Histograms are very similar to bar charts. They represent the number of data points in a range. Histograms are used to display numerical variables in bins. The difference between the histograms and bar charts is that bar charts represent categorical variables while histograms represent numeric variables.<\/p>\n<h2>Making Histogram in R<\/h2>\n<p>Histograms in R are also similarly easy to make. We can use the <strong>hist()<\/strong> command to make histograms in R.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">hist(airquality$Temp)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/11.barplots-and-histograms-in-r-hist-function.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78552\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/11.barplots-and-histograms-in-r-hist-function.png\" alt=\"Histograms in R\" width=\"599\" height=\"398\" \/><\/a><\/p>\n<h2>Customizing Histogram in R<\/h2>\n<h3>1. Adding a name to the plot<\/h3>\n<p>The main argument can be used to add a title to the graph.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">hist(airquality$Temp,\n     main=\"Temperatures in NY city\")\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/12.barplots-and-histograms-in-r-histogram-title.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78553\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/12.barplots-and-histograms-in-r-histogram-title.png\" alt=\"R histograms\" width=\"599\" height=\"398\" \/><\/a><\/p>\n<h3>2. Adding labels to the axes<\/h3>\n<p>The xlab and the ylab arguments can be used to add labels to the X and Y axes of the graph.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">hist(airquality$Temp,\n     main=\"Temperatures in NY city\",\n     xlab=\"Temperature\",\n     ylab=\"Frequency\")\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/13.barplots-and-histograms-in-r-axes-labels-histograms.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78554\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/13.barplots-and-histograms-in-r-axes-labels-histograms.png\" alt=\"Histograms in R\" width=\"599\" height=\"398\" \/><\/a><\/p>\n<h3>3. Changing the colors of the bars<\/h3>\n<p>The col argument can help with changing the color of the bars inside the graph.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">hist(airquality$Temp,\n     main=\"Temperatures in NY city\",\n     xlab=\"Temperature\",\n     ylab=\"Frequency\",\n     col=\"green\")\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/14.barplots-and-histograms-in-r-histogram-colors.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78555\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/14.barplots-and-histograms-in-r-histogram-colors.png\" alt=\"R Histograms\" width=\"599\" height=\"398\" \/><\/a><\/p>\n<h3>4. Adding borders to the bars<\/h3>\n<p>To add borders to the bars in the graph, we can use the border argument.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">hist(airquality$Temp,\n     main=\"Temperatures in NY city\",\n     xlab=\"Temperature\",\n     ylab=\"Frequency\",\n     col=\"green\",\n     border=\"red\")\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/15.barplots-and-histograms-in-r-histogram-border.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78556\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/15.barplots-and-histograms-in-r-histogram-border.png\" alt=\"Histograms in R\" width=\"599\" height=\"398\" \/><\/a><\/p>\n<h2>Histogram in R Using the Ggplot2 Package<\/h2>\n<p>As we have learnt in previous article of bar ploat that Ggplot2 is probably the best graphics and visualization package available in R. In this section of histograms in R tutorial, we are going to take a look at how to make histograms in R using the ggplot2 package.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">ggplot(airquality, aes(x = Ozone)) +\n  geom_histogram(aes(y = ..count..), binwidth = 5,\n                 colour = \"goldenrod2\", fill = \"gold1\") +\n  scale_x_continuous(name = \"Mean ozone in\\nparts per billion\",\n                     breaks = seq(0, 175, 25),\n                     limits=c(0, 175)) +\n  scale_y_continuous(name = \"Count\") +\n  ggtitle(\"Frequency histogram of mean ozone\")\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/17.barplots-and-histograms-in-r-histogram-with-ggplot2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78558\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/17.barplots-and-histograms-in-r-histogram-with-ggplot2.png\" alt=\"R Histograms\" width=\"652\" height=\"425\" \/><\/a><\/p>\n<h2>Summary<\/h2>\n<p>To conclude, in this chapter of TechVidvan\u2019s R tutorial series, we learned all about histogram in R. We looked at how to make and customize it in R. Finally, we learned how to make histograms in R using the ggplot2 package.<\/p>\n<p><strong>Hope the article was useful for you. Share your feedback in the comment section.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this TechVidvan R Tutorial series, we will learn what is histogram in R, how to implement it. We will also look at how to plot them using the ggplot2 package. So, without any&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":78561,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1020],"tags":[2577],"class_list":["post-78541","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-histograms-in-r"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Histogram in R - Implementation and Customization - TechVidvan<\/title>\n<meta name=\"description\" content=\"Histogram in R - Learn how to create histogram in R using hist() command, how to customize the R histograms. Learn how to use Ggplot2 package for histograms\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Histogram in R - Implementation and Customization - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Histogram in R - Learn how to create histogram in R using hist() command, how to customize the R histograms. Learn how to use Ggplot2 package for histograms\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-05T11:04:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Histograms-in-R.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Histogram in R - Implementation and Customization - TechVidvan","description":"Histogram in R - Learn how to create histogram in R using hist() command, how to customize the R histograms. Learn how to use Ggplot2 package for histograms","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/","og_locale":"en_US","og_type":"article","og_title":"Histogram in R - Implementation and Customization - TechVidvan","og_description":"Histogram in R - Learn how to create histogram in R using hist() command, how to customize the R histograms. Learn how to use Ggplot2 package for histograms","og_url":"https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-05-05T11:04:05+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Histograms-in-R.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Histogram in R &#8211; Implementation and Customization","datePublished":"2020-05-05T11:04:05+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/"},"wordCount":329,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Histograms-in-R.jpg","keywords":["Histograms in r"],"articleSection":["R Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/","url":"https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/","name":"Histogram in R - Implementation and Customization - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Histograms-in-R.jpg","datePublished":"2020-05-05T11:04:05+00:00","description":"Histogram in R - Learn how to create histogram in R using hist() command, how to customize the R histograms. Learn how to use Ggplot2 package for histograms","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Histograms-in-R.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Histograms-in-R.jpg","width":802,"height":420,"caption":"Histogram in R"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/histogram-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Histogram in R &#8211; Implementation and Customization"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/78541","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=78541"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/78541\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/78561"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=78541"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=78541"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=78541"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}