{"id":13711370,"url":"https://github.com/Sayani07/gghdr","last_synced_at":"2025-05-06T20:32:49.611Z","repository":{"id":56934158,"uuid":"227281447","full_name":"Sayani07/gghdr","owner":"Sayani07","description":"Plots of highest density regions (HDR) for ggplot2","archived":false,"fork":false,"pushed_at":"2024-02-07T09:54:49.000Z","size":27061,"stargazers_count":47,"open_issues_count":7,"forks_count":5,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-05-19T00:29:55.579Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://sayani07.github.io/gghdr/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sayani07.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-11T05:10:38.000Z","updated_at":"2024-07-15T21:37:35.955Z","dependencies_parsed_at":"2024-01-17T16:57:17.805Z","dependency_job_id":"7caeecd6-06d6-4f50-8d8c-8795e547e383","html_url":"https://github.com/Sayani07/gghdr","commit_stats":{"total_commits":225,"total_committers":8,"mean_commits":28.125,"dds":0.6266666666666667,"last_synced_commit":"27fbf584cd5561129f8c704a7dceb5e984876671"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sayani07%2Fgghdr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sayani07%2Fgghdr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sayani07%2Fgghdr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sayani07%2Fgghdr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sayani07","download_url":"https://codeload.github.com/Sayani07/gghdr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224528399,"owners_count":17326359,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T23:01:07.521Z","updated_at":"2024-11-13T21:31:48.565Z","avatar_url":"https://github.com/Sayani07.png","language":"R","funding_links":[],"categories":["Plot layers","R"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\nset.seed(1234)\n```\n\n# gghdr \u003cimg src=\"man/figures/logo.png\" align=\"right\" width=\"120\" /\u003e\n\n\u003c!-- badges: start --\u003e\n[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)\n[![R-CMD-check](https://github.com/Sayani07/gghdr/workflows/R-CMD-check/badge.svg)](https://github.com/Sayani07/gghdr/actions)\n\u003c!-- [![Codecov test coverage](https://codecov.io/gh/ropenscilabs/gghdr/branch/master/graph/badge.svg)](https://codecov.io/gh/ropenscilabs/gghdr?branch=master) --\u003e\n\u003c!-- badges: end --\u003e\n\n \nPackage `gghdr` helps to visualize Highest Density Regions (HDR) in one and two dimensions. HDRs\nare useful in displaying multimodality in the distribution. This work draws inspiration from the the package [`hdrcde`](https://pkg.robjhyndman.com/hdrcde/) developed by [Rob Hyndman](https://robjhyndman.com/) and provide a framework for displaying HDRs under `ggplot2` framework.\n\n# Installation\n\nYou could install the stable version on CRAN:\n\n```{r install, eval = FALSE}\ninstall.packages(\"gghdr\")\n```\n\nYou could install the development version from Github using:\n\n```{r install_github, eval = FALSE}\n# install.packages(\"remotes\")\nremotes::install_github(\"Sayani07/gghdr\")\n```\n\n# An overview of gghdr\n\nThere are several statistical methods to summarize a distribution by region of the sample space covering certain probability. For example, in a traditional boxplot, the central box bounded by the interquartile range represents 50% coverage and whiskers represent 99% coverage for large samples. The method of summarizing a distribution using highest density regions is useful for analysing multimodal distributions. We illustrate this by exploring the data set `faithful` which contains the waiting time and duration of eruptions for the old faithful geyser in the Yellowstone National Park, USA.\n\n```{r setup, echo=FALSE, message=FALSE}\nlibrary(hdrcde)\n```\n\n```{r boxplot}\nlibrary(ggplot2)\nggplot(faithful, aes(y=eruptions)) + geom_boxplot()\n```\n\n\n \u003c!-- In both HDR and box plots, the interquartile range or 50% HDR will have a coverage probability of 50%. --\u003e\n\n\n\u003c!-- # ```{r hdrcde-boxplot_more, echo=TRUE, eval = FALSE} --\u003e\n\u003c!-- # hdr.boxplot(x, prob = c(99, 50), h = hdrbw(BoxCox(x, lambda), --\u003e\n\u003c!-- #   mean(prob)), lambda = 1, boxlabels = \"\", col = gray((9:1)/10), --\u003e\n\u003c!-- #   main = \"\", xlab = \"\", ylab = \"\", pch = 1, border = 1, --\u003e\n\u003c!-- #   outline = TRUE, space = 0.25, ...) --\u003e\n\u003c!-- # ``` --\u003e\n\nWe can use `geom_hdr_boxplot` to display the same variable. Along with displaying the 99% and 50% highest density regions, it also shows the local mode in each of the regions. This shows that eruption times are likely to be around 4.5 minutes or 2 minutes, but rarely for around 3 minutes. This insight was not apparent in the above boxplot. \n\n\n```{r gg_hdr-boxplot, echo=TRUE, eval = T}\nlibrary(gghdr)\nlibrary(ggplot2)\nggplot(faithful, aes(y = eruptions)) + \n  geom_hdr_boxplot(prob = c(.5, 0.99), fill = \"blue\") + \n  theme_minimal()\n```\n\nIt can be interesting to supplement a scatterplot with marginal distributions of one or both variables to enhance insights into the relationship between the two variables. This is possible through `geom_hdr_rug`. This shows two clear clusters, one with shorter waiting times and shorter eruptions (around 2 minutes) and another with longer waiting times and longer eruptions (around 4.5 minutes). The `geom_hdr_rug` adds to this information by displaying the highest density region of eruption time covering 50% and 99%.\n\n\n\u003c!-- eruptions with longer waiting times tend to be longer in duration (around 4.5 minutes) and with shorter waiting times are most likely to last shorter (around 2 minutes).  --\u003e\n\n```{r hdr_rug}\nggplot(faithful) +\n  geom_point(aes(x = eruptions, y = waiting)) + \n  geom_hdr_rug(aes(x = eruptions), prob = c(0.99, 0.5), fill = \"blue\")\n```\n\nThe previous example can be extended to allow displaying the scatterplot with points coloured according to the bivariate highest density regions using `hdr_bin`.`hdr_bin` can also be mapped to only the x-axis or y-axis to show the marginal distribution of any one variable. This figure enriches the information in the scatterplot by emphasizing the highest bivariate density regions covering 50%, 90%, 99%, and more than 99% coverage.\n\n\n```{r hdr_bin}\nggplot(data = faithful, aes(x = waiting, y=eruptions)) +\n  geom_point(aes(colour = hdr_bin(x = waiting, y = eruptions))) +\n  scale_colour_viridis_d(direction = -1) \n```\n\nYou can read more about gghdr in the [vignette](https://sayani07.github.io/gghdr/).\n\n[![ropensci_footer](https://ropensci.org/public_images/ropensci_footer.png)](https://ropensci.org)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSayani07%2Fgghdr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSayani07%2Fgghdr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSayani07%2Fgghdr/lists"}