{"id":13400641,"url":"https://github.com/LKremer/ggpointdensity","last_synced_at":"2025-03-14T06:31:48.749Z","repository":{"id":56936802,"uuid":"195246060","full_name":"LKremer/ggpointdensity","owner":"LKremer","description":":chart_with_upwards_trend: :bar_chart: Introduces geom_pointdensity(): A Cross Between a Scatter Plot and a 2D Density Plot.","archived":false,"fork":false,"pushed_at":"2024-05-16T11:22:20.000Z","size":3807,"stargazers_count":409,"open_issues_count":8,"forks_count":24,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-09-30T21:08:45.302Z","etag":null,"topics":["2d-density-plot","density-visualization","geom","ggplot-extension","ggplot2","ggplot2-enhancements","ggplot2-geoms","neighboring-points","r","r-package","r-stats","rstats","scatter-plot","visualization"],"latest_commit_sha":null,"homepage":"","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/LKremer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-07-04T13:22:15.000Z","updated_at":"2024-09-23T14:32:20.000Z","dependencies_parsed_at":"2022-08-21T01:10:14.354Z","dependency_job_id":"c755cea9-1c98-4996-bbd3-6eea805dd788","html_url":"https://github.com/LKremer/ggpointdensity","commit_stats":{"total_commits":35,"total_committers":6,"mean_commits":5.833333333333333,"dds":0.4571428571428572,"last_synced_commit":"02f3ab24eb22e3e34294baeca23a8998db43be70"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LKremer%2Fggpointdensity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LKremer%2Fggpointdensity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LKremer%2Fggpointdensity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LKremer%2Fggpointdensity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LKremer","download_url":"https://codeload.github.com/LKremer/ggpointdensity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243141235,"owners_count":20242818,"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":["2d-density-plot","density-visualization","geom","ggplot-extension","ggplot2","ggplot2-enhancements","ggplot2-geoms","neighboring-points","r","r-package","r-stats","rstats","scatter-plot","visualization"],"created_at":"2024-07-30T19:00:54.179Z","updated_at":"2025-03-14T06:31:48.742Z","avatar_url":"https://github.com/LKremer.png","language":"R","funding_links":[],"categories":["R","Plot layers","ggplot"],"sub_categories":["Additional Plot Types"],"readme":"# ggpointdensity\n[![CRAN\\_Status\\_Badge](https://www.r-pkg.org/badges/version/ggpointdensity)](https://cran.r-project.org/package=ggpointdensity) \n[![Downloads](https://cranlogs.r-pkg.org/badges/last-month/ggpointdensity?color=brightgreen)](https://cran.r-project.org/package=ggpointdensity)\n\nIntroduces `geom_pointdensity()`: A cross between a scatter plot and a 2D density plot.\n\n\u003cimg src=\"img/pointdensity_logo.png\" width=\"60%\" /\u003e\n\n\n## Installation\nTo install the package, type this command in R:\n``` r\ninstall.packages(\"ggpointdensity\")\n\n# Alternatively, you can install the latest\n# development version from GitHub:\nif (!requireNamespace(\"devtools\", quietly = TRUE))\n    install.packages(\"devtools\")\ndevtools::install_github(\"LKremer/ggpointdensity\")\n```\n\n## Motivation\nThere are several ways to visualize data points on a 2D coordinate system:\nIf you have lots of data points on top of each other, `geom_point()` fails to\ngive you an estimate of how many points are overlapping.\n`geom_density2d()` and `geom_bin2d()` solve this issue, but they make it impossible\nto investigate individual outlier points, which may be of interest.\n\n\u003cimg src=\"img/scatter_dens_bin2d.png\" width=\"100%\" /\u003e\n\n`geom_pointdensity()` aims to solve this problem by combining the best of both\nworlds: individual points are colored by the number of neighboring points.\nThis allows you to see the overall distribution, as well as individual points.\n\n\u003cimg src=\"img/pointdensity.png\" width=\"50%\" /\u003e\n\n## Changelog\nAdded `method` argument and renamed the `n_neighbor` stat to `density`. The available options\nare `method=\"auto\"`,\n`method=\"default\"` and `method=\"kde2d\"`. `default` is the regular n_neighbor calculation\nas in the CRAN package. `kde2d` uses 2D kernel density estimation to estimate the point density\n(credits to @slowkow).\nThis method is slower for few points, but faster for many (ca. \u003e20k) points. By default,\n`method=\"auto\"` picks either `kde2d` or `default` depending on the number of points.\n\n## Demo\nGenerate some toy data and visualize it with `geom_pointdensity()`:\n``` r\nlibrary(ggplot2)\nlibrary(dplyr)\nlibrary(viridis)\nlibrary(ggpointdensity)\n\ndat \u003c- bind_rows(\n  tibble(x = rnorm(7000, sd = 1),\n         y = rnorm(7000, sd = 10),\n         group = \"foo\"),\n  tibble(x = rnorm(3000, mean = 1, sd = .5),\n         y = rnorm(3000, mean = 7, sd = 5),\n         group = \"bar\"))\n\nggplot(data = dat, mapping = aes(x = x, y = y)) +\n  geom_pointdensity() +\n  scale_color_viridis()\n```\n\n\u003cimg src=\"img/pointdensity.png\" width=\"50%\" /\u003e\n\nEach point is colored according to the number of neighboring points.\n(Note: this here is the dev branch, where I decided to plot the density estimate\ninstead of n_neighbors now.)\nThe distance threshold to consider two points as neighbors (smoothing\nbandwidth) can be adjusted with the `adjust` argument, where `adjust = 0.5`\nmeans use half of the default bandwidth.\n``` r\nggplot(data = dat, mapping = aes(x = x, y = y)) +\n  geom_pointdensity(adjust = .1) +\n  scale_color_viridis()\n \nggplot(data = dat, mapping = aes(x = x, y = y)) +\n  geom_pointdensity(adjust = 4) +\n  scale_color_viridis()\n```\n\u003cimg src=\"img/pointdensity_adj.png\" width=\"100%\" /\u003e\n\nOf course you can combine the geom with standard `ggplot2` features\nsuch as facets...\n\n``` r\n# Facetting by group\nggplot(data = dat, mapping = aes(x = x, y = y)) +\n  geom_pointdensity() +\n  scale_color_viridis() +\n  facet_wrap( ~ group)\n```\n\n\u003cimg src=\"img/pointdensity_facet.png\" width=\"75%\" /\u003e\n\n... or point shape and size:\n``` r\ndat_subset \u003c- sample_frac(dat, .1)  # smaller data set\nggplot(data = dat_subset, mapping = aes(x = x, y = y)) +\n  geom_pointdensity(size = 3, shape = 17) +\n  scale_color_viridis()\n```\n\n\u003cimg src=\"img/pointdensity_shape.png\" width=\"50%\" /\u003e\n\nZooming into the axis works as well, keep in mind that `xlim()` and\n`ylim()` change the density since they remove data points.\nIt may be better to use `coord_cartesian()` instead.\n\n``` r\nggplot(data = dat, mapping = aes(x = x, y = y)) +\n  geom_pointdensity() +\n  scale_color_viridis() +\n  xlim(c(-1, 3)) + ylim(c(-5, 15))\n\nggplot(data = dat, mapping = aes(x = x, y = y)) +\n  geom_pointdensity() +\n  scale_color_viridis() +\n  coord_cartesian(xlim = c(-1, 3), ylim = c(-5, 15))\n```\n\n\u003cimg src=\"img/pointdensity_zoom.png\" width=\"100%\" /\u003e\n\n## Authors\nLukas PM Kremer ([@LPMKremer](https://twitter.com/LPMKremer/)) and Simon Anders ([@s_anders_m](https://twitter.com/s_anders_m/)), 2019\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLKremer%2Fggpointdensity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLKremer%2Fggpointdensity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLKremer%2Fggpointdensity/lists"}