{"id":8436,"date":"2019-01-16T03:27:04","date_gmt":"2019-01-16T01:27:04","guid":{"rendered":"https:\/\/www.datanovia.com\/en\/?p=8436"},"modified":"2019-12-25T10:53:48","modified_gmt":"2019-12-25T08:53:48","slug":"r-histogram-example-quick-reference","status":"publish","type":"post","link":"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/","title":{"rendered":"R Histogram Example Quick Reference"},"content":{"rendered":"<div id=\"rdoc\">\n<p>This article shows some <strong>R histogram examples<\/strong>.<\/p>\n<div id=\"demo-data\" class=\"section level2\">\n<h2>Demo data<\/h2>\n<p>Weight data by sex:<\/p>\n<pre class=\"r\"><code>set.seed(1234)\r\nwdata = data.frame(\r\n        sex = factor(rep(c(\"F\", \"M\"), each=200)),\r\n        weight = c(rnorm(200, 55), rnorm(200, 58))\r\n        )\r\n\r\nhead(wdata, 4)<\/code><\/pre>\n<pre><code>##   sex weight\r\n## 1   F   53.8\r\n## 2   F   55.3\r\n## 3   F   56.1\r\n## 4   F   52.7<\/code><\/pre>\n<\/div>\n<div id=\"r-base-plot\" class=\"section level2\">\n<h2>R base plot<\/h2>\n<pre class=\"r\"><code>hist(wdata$weight, breaks = 30, col = \"steelblue\", frame = FALSE)<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/r-tutorial\/figures\/003-r-histogram-example-base-plot-1.png\" width=\"384\" \/><\/p>\n<\/div>\n<div id=\"ggplot2-package\" class=\"section level2\">\n<h2>GGPlot2 package<\/h2>\n<pre class=\"r\"><code>library(ggplot2)\r\ntheme_set(theme_bw())\r\n# Basic plot\r\nggplot(wdata, aes(x = weight)) +\r\n  geom_histogram(bins = 30) \r\n\r\n# Change fill color by sex group\r\nggplot(wdata, aes(x = weight)) +\r\n  geom_histogram(aes(fill = sex), bins = 30, alpha = 0.5,\r\n                 position = position_dodge()) +\r\n  scale_fill_viridis_d() <\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/r-tutorial\/figures\/003-r-histogram-example-ggplot2-1.png\" width=\"288\" \/><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/r-tutorial\/figures\/003-r-histogram-example-ggplot2-2.png\" width=\"288\" \/><\/p>\n<\/div>\n<div id=\"ggpubr-package\" class=\"section level2\">\n<h2>GGPubr package<\/h2>\n<p>ggpubr: ggplot2-based publication ready plots<\/p>\n<pre class=\"r\"><code>library(ggpubr)\r\n\r\n# Basic plots\r\ngghistogram(wdata, x = \"weight\", fill = \"steelblue\", alpha = 1)\r\n\r\n# Change color by sex group\r\ngghistogram(\r\n  wdata, x = \"weight\", color = \"sex\",\r\n  palette = c(\"#00AFBB\", \"#E7B800\")\r\n  )<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/r-tutorial\/figures\/003-r-histogram-example-ggpubr-1.png\" width=\"288\" \/><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/r-tutorial\/figures\/003-r-histogram-example-ggpubr-2.png\" width=\"288\" \/><\/p>\n<\/div>\n<\/div>\n<p><!--end rdoc--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article shows some R histogram examples. Demo data Weight data by sex: set.seed(1234) wdata = data.frame( sex = factor(rep(c(&#8220;F&#8221;, &#8220;M&#8221;), each=200)), weight = c(rnorm(200, 55), rnorm(200, 58)) ) head(wdata, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7831,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rating_form_position":"","rating_results_position":"","mr_structured_data_type":"","footnotes":""},"categories":[126],"tags":[],"class_list":["post-8436","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r-tips-and-tricks"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>R Histogram Example Quick Reference - Datanovia<\/title>\n<meta name=\"description\" content=\"This article shows some R histogram examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"R Histogram Example Quick Reference - Datanovia\" \/>\n<meta property=\"og:description\" content=\"This article shows some R histogram examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/\" \/>\n<meta property=\"og:site_name\" content=\"Datanovia\" \/>\n<meta property=\"article:published_time\" content=\"2019-01-16T01:27:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-12-25T08:53:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030228.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Alboukadel\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alboukadel\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/\"},\"author\":{\"name\":\"Alboukadel\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/person\/7767cf2bd5c91a1610c6eb53a0ff069e\"},\"headline\":\"R Histogram Example Quick Reference\",\"datePublished\":\"2019-01-16T01:27:04+00:00\",\"dateModified\":\"2019-12-25T08:53:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/\"},\"wordCount\":31,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030228.jpg\",\"articleSection\":[\"R Tips and Tricks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/\",\"url\":\"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/\",\"name\":\"R Histogram Example Quick Reference - Datanovia\",\"isPartOf\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030228.jpg\",\"datePublished\":\"2019-01-16T01:27:04+00:00\",\"dateModified\":\"2019-12-25T08:53:48+00:00\",\"description\":\"This article shows some R histogram examples.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/#primaryimage\",\"url\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030228.jpg\",\"contentUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030228.jpg\",\"width\":1024,\"height\":512},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.datanovia.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"R Histogram Example Quick Reference\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#website\",\"url\":\"https:\/\/www.datanovia.com\/en\/\",\"name\":\"Datanovia\",\"description\":\"Data Mining and Statistics for Decision Support\",\"publisher\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.datanovia.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#organization\",\"name\":\"Datanovia\",\"url\":\"https:\/\/www.datanovia.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png\",\"contentUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png\",\"width\":98,\"height\":99,\"caption\":\"Datanovia\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/person\/7767cf2bd5c91a1610c6eb53a0ff069e\",\"name\":\"Alboukadel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ed3108646c5c7c3d188324ab972f96ad7d9975b41b94014d7f68257791be395a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ed3108646c5c7c3d188324ab972f96ad7d9975b41b94014d7f68257791be395a?s=96&d=mm&r=g\",\"caption\":\"Alboukadel\"},\"url\":\"https:\/\/www.datanovia.com\/en\/blog\/author\/kassambara\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"R Histogram Example Quick Reference - Datanovia","description":"This article shows some R histogram examples.","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:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/","og_locale":"en_US","og_type":"article","og_title":"R Histogram Example Quick Reference - Datanovia","og_description":"This article shows some R histogram examples.","og_url":"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/","og_site_name":"Datanovia","article_published_time":"2019-01-16T01:27:04+00:00","article_modified_time":"2019-12-25T08:53:48+00:00","og_image":[{"width":1024,"height":512,"url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030228.jpg","type":"image\/jpeg"}],"author":"Alboukadel","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Alboukadel","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/#article","isPartOf":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/"},"author":{"name":"Alboukadel","@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/person\/7767cf2bd5c91a1610c6eb53a0ff069e"},"headline":"R Histogram Example Quick Reference","datePublished":"2019-01-16T01:27:04+00:00","dateModified":"2019-12-25T08:53:48+00:00","mainEntityOfPage":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/"},"wordCount":31,"commentCount":0,"publisher":{"@id":"https:\/\/www.datanovia.com\/en\/#organization"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/#primaryimage"},"thumbnailUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030228.jpg","articleSection":["R Tips and Tricks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/","url":"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/","name":"R Histogram Example Quick Reference - Datanovia","isPartOf":{"@id":"https:\/\/www.datanovia.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/#primaryimage"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/#primaryimage"},"thumbnailUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030228.jpg","datePublished":"2019-01-16T01:27:04+00:00","dateModified":"2019-12-25T08:53:48+00:00","description":"This article shows some R histogram examples.","breadcrumb":{"@id":"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/#primaryimage","url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030228.jpg","contentUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/P1030228.jpg","width":1024,"height":512},{"@type":"BreadcrumbList","@id":"https:\/\/www.datanovia.com\/en\/blog\/r-histogram-example-quick-reference\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.datanovia.com\/en\/"},{"@type":"ListItem","position":2,"name":"R Histogram Example Quick Reference"}]},{"@type":"WebSite","@id":"https:\/\/www.datanovia.com\/en\/#website","url":"https:\/\/www.datanovia.com\/en\/","name":"Datanovia","description":"Data Mining and Statistics for Decision Support","publisher":{"@id":"https:\/\/www.datanovia.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.datanovia.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.datanovia.com\/en\/#organization","name":"Datanovia","url":"https:\/\/www.datanovia.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png","contentUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png","width":98,"height":99,"caption":"Datanovia"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/person\/7767cf2bd5c91a1610c6eb53a0ff069e","name":"Alboukadel","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ed3108646c5c7c3d188324ab972f96ad7d9975b41b94014d7f68257791be395a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ed3108646c5c7c3d188324ab972f96ad7d9975b41b94014d7f68257791be395a?s=96&d=mm&r=g","caption":"Alboukadel"},"url":"https:\/\/www.datanovia.com\/en\/blog\/author\/kassambara\/"}]}},"multi-rating":{"mr_rating_results":[]},"_links":{"self":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/posts\/8436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/comments?post=8436"}],"version-history":[{"count":1,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/posts\/8436\/revisions"}],"predecessor-version":[{"id":8437,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/posts\/8436\/revisions\/8437"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media\/7831"}],"wp:attachment":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media?parent=8436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/categories?post=8436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/tags?post=8436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}