{"id":15908,"date":"2020-04-27T15:55:16","date_gmt":"2020-04-27T14:55:16","guid":{"rendered":"https:\/\/www.datanovia.com\/en\/?post_type=dt_lessons&#038;p=15908"},"modified":"2020-04-27T16:27:03","modified_gmt":"2020-04-27T15:27:03","slug":"highchart-interactive-density-and-histogram-plots-in-r","status":"publish","type":"dt_lessons","link":"https:\/\/www.datanovia.com\/en\/lessons\/highchart-interactive-density-and-histogram-plots-in-r\/","title":{"rendered":"Highchart Interactive Density and Histogram Plots in R"},"content":{"rendered":"<div id=\"rdoc\">\n<p>You will learn how to create <strong>interactive density distribution and histogram plots<\/strong> using the <em>highcharter<\/em> R package.<\/p>\n<p>Contents:<\/p>\n<div id=\"TOC\">\n<ul>\n<li><a href=\"#loading-required-r-packages\">Loading required R packages<\/a><\/li>\n<li><a href=\"#data-preparation\">Data preparation<\/a><\/li>\n<li><a href=\"#density-plots\">Density plots<\/a>\n<ul>\n<li><a href=\"#basic-density-plots\">Basic density plots<\/a><\/li>\n<li><a href=\"#grouped-density-plots\">Grouped density plots<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#histograms\">Histograms<\/a><\/li>\n<\/ul>\n<\/div>\n<div id=\"loading-required-r-packages\" class=\"section level2\">\n<h2>Loading required R packages<\/h2>\n<pre class=\"r\"><code># Load required R packages\r\nlibrary(dplyr)\r\nlibrary(highcharter) \r\n# Set highcharter options\r\noptions(highcharter.theme = hc_theme_smpl(tooltip = list(valueDecimals = 2)))<\/code><\/pre>\n<\/div>\n<div id=\"data-preparation\" class=\"section level2\">\n<h2>Data preparation<\/h2>\n<p>Create some data (<code>wdata<\/code>) containing the weights by sex (M for male; F for female):<\/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=\"density-plots\" class=\"section level2\">\n<h2>Density plots<\/h2>\n<div id=\"basic-density-plots\" class=\"section level3\">\n<h3>Basic density plots<\/h3>\n<pre class=\"r\"><code>hc &lt;- hchart(\r\n  density(wdata$weight), \r\n  type = \"area\", name = \"Weight\"\r\n  )<\/code><\/pre>\n<pre class=\"r\"><code>hc<\/code><\/pre>\n<p><iframe width=\"95%\" height=\"450\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/highcharter\/figures\/012-highcharter-distribution-basic-density-plots.html\" frameborder=\"2\"><br \/>\n<\/iframe><\/p>\n<\/div>\n<div id=\"grouped-density-plots\" class=\"section level3\">\n<h3>Grouped density plots<\/h3>\n<pre class=\"r\"><code>f &lt;- wdata %&gt;% filter(sex == \"F\")\r\nm &lt;- wdata %&gt;% filter(sex == \"M\")\r\nhc &lt;- hchart(\r\n  density(m$weight), type = \"area\", \r\n  color = \"steelblue\", name = \"Male\"\r\n  ) %&gt;%\r\n  hc_add_series(\r\n    density(f$weight), type = \"area\",\r\n    color = \"#B71C1C\", \r\n    name = \"Female\"\r\n    )<\/code><\/pre>\n<pre class=\"r\"><code>hc<\/code><\/pre>\n<p><iframe width=\"95%\" height=\"450\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/highcharter\/figures\/012-highcharter-distribution-grouped-density-plots.html\" frameborder=\"2\"><br \/>\n<\/iframe><\/p>\n<\/div>\n<\/div>\n<div id=\"histograms\" class=\"section level2\">\n<h2>Histograms<\/h2>\n<pre class=\"r\"><code>hc &lt;- hchart(\r\n  wdata$weight, \r\n  color = \"#B71C1C\", name = \"Weight\"\r\n  )<\/code><\/pre>\n<pre class=\"r\"><code>hc<\/code><\/pre>\n<p><iframe width=\"95%\" height=\"450\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/highcharter\/figures\/012-highcharter-distribution-histograms.html\" frameborder=\"2\"><br \/>\n<\/iframe><\/p>\n<\/div>\n<\/div>\n<p><!--end rdoc--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You will learn how to create interactive density distribution and histogram plots using the highcharter R package<\/p>\n","protected":false},"author":1,"featured_media":9131,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","class_list":["post-15908","dt_lessons","type-dt_lessons","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Highchart Interactive Density and Histogram Plots in R: The Essentials - Datanovia<\/title>\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\/lessons\/highchart-interactive-density-and-histogram-plots-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Highchart Interactive Density and Histogram Plots in R: The Essentials - Datanovia\" \/>\n<meta property=\"og:description\" content=\"You will learn how to create interactive density distribution and histogram plots using the highcharter R package\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.datanovia.com\/en\/lessons\/highchart-interactive-density-and-histogram-plots-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Datanovia\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-27T15:27:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/P1040350.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=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.datanovia.com\\\/en\\\/lessons\\\/highchart-interactive-density-and-histogram-plots-in-r\\\/\",\"url\":\"https:\\\/\\\/www.datanovia.com\\\/en\\\/lessons\\\/highchart-interactive-density-and-histogram-plots-in-r\\\/\",\"name\":\"Highchart Interactive Density and Histogram Plots in R: The Essentials - Datanovia\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.datanovia.com\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.datanovia.com\\\/en\\\/lessons\\\/highchart-interactive-density-and-histogram-plots-in-r\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.datanovia.com\\\/en\\\/lessons\\\/highchart-interactive-density-and-histogram-plots-in-r\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.datanovia.com\\\/en\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/P1040350.jpg\",\"datePublished\":\"2020-04-27T14:55:16+00:00\",\"dateModified\":\"2020-04-27T15:27:03+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.datanovia.com\\\/en\\\/lessons\\\/highchart-interactive-density-and-histogram-plots-in-r\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.datanovia.com\\\/en\\\/lessons\\\/highchart-interactive-density-and-histogram-plots-in-r\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.datanovia.com\\\/en\\\/lessons\\\/highchart-interactive-density-and-histogram-plots-in-r\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.datanovia.com\\\/en\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/P1040350.jpg\",\"contentUrl\":\"https:\\\/\\\/www.datanovia.com\\\/en\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/P1040350.jpg\",\"width\":1024,\"height\":512},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.datanovia.com\\\/en\\\/lessons\\\/highchart-interactive-density-and-histogram-plots-in-r\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.datanovia.com\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Lessons\",\"item\":\"https:\\\/\\\/www.datanovia.com\\\/en\\\/lessons\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Highchart Interactive Density and Histogram Plots in R\"}]},{\"@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\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Highchart Interactive Density and Histogram Plots in R: The Essentials - Datanovia","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\/lessons\/highchart-interactive-density-and-histogram-plots-in-r\/","og_locale":"en_US","og_type":"article","og_title":"Highchart Interactive Density and Histogram Plots in R: The Essentials - Datanovia","og_description":"You will learn how to create interactive density distribution and histogram plots using the highcharter R package","og_url":"https:\/\/www.datanovia.com\/en\/lessons\/highchart-interactive-density-and-histogram-plots-in-r\/","og_site_name":"Datanovia","article_modified_time":"2020-04-27T15:27:03+00:00","og_image":[{"width":1024,"height":512,"url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/P1040350.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.datanovia.com\/en\/lessons\/highchart-interactive-density-and-histogram-plots-in-r\/","url":"https:\/\/www.datanovia.com\/en\/lessons\/highchart-interactive-density-and-histogram-plots-in-r\/","name":"Highchart Interactive Density and Histogram Plots in R: The Essentials - Datanovia","isPartOf":{"@id":"https:\/\/www.datanovia.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.datanovia.com\/en\/lessons\/highchart-interactive-density-and-histogram-plots-in-r\/#primaryimage"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/lessons\/highchart-interactive-density-and-histogram-plots-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/P1040350.jpg","datePublished":"2020-04-27T14:55:16+00:00","dateModified":"2020-04-27T15:27:03+00:00","breadcrumb":{"@id":"https:\/\/www.datanovia.com\/en\/lessons\/highchart-interactive-density-and-histogram-plots-in-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.datanovia.com\/en\/lessons\/highchart-interactive-density-and-histogram-plots-in-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/lessons\/highchart-interactive-density-and-histogram-plots-in-r\/#primaryimage","url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/P1040350.jpg","contentUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2019\/05\/P1040350.jpg","width":1024,"height":512},{"@type":"BreadcrumbList","@id":"https:\/\/www.datanovia.com\/en\/lessons\/highchart-interactive-density-and-histogram-plots-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.datanovia.com\/en\/"},{"@type":"ListItem","position":2,"name":"Lessons","item":"https:\/\/www.datanovia.com\/en\/lessons\/"},{"@type":"ListItem","position":3,"name":"Highchart Interactive Density and Histogram Plots in R"}]},{"@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\/"}}]}},"multi-rating":{"mr_rating_results":[]},"_links":{"self":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons\/15908","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons"}],"about":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/types\/dt_lessons"}],"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=15908"}],"version-history":[{"count":1,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons\/15908\/revisions"}],"predecessor-version":[{"id":15910,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons\/15908\/revisions\/15910"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media\/9131"}],"wp:attachment":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media?parent=15908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}