ggpointdensity

:chart_with_upwards_trend: :bar_chart: Introduces geom_pointdensity(): A Cross Between a Scatter Plot and a 2D Density Plot.

https://github.com/lkremer/ggpointdensity

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 7 committers (14.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.1%) to scientific vocabulary

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

Keywords from Contributors

bioinformatics visualisation
Last synced: 6 months ago · JSON representation

Repository

:chart_with_upwards_trend: :bar_chart: Introduces geom_pointdensity(): A Cross Between a Scatter Plot and a 2D Density Plot.

Basic Info
  • Host: GitHub
  • Owner: LKremer
  • License: gpl-3.0
  • Language: R
  • Default Branch: master
  • Homepage:
  • Size: 26.7 MB
Statistics
  • Stars: 436
  • Watchers: 5
  • Forks: 27
  • Open Issues: 8
  • Releases: 0
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
Created over 6 years ago · Last pushed 9 months ago
Metadata Files
Readme License

README.md

ggpointdensity

R-CMD-check CRAN\_Status\_Badge Downloads <!-- badges: end -->

Introduces geom_pointdensity(): A cross between a scatter plot and a 2D density plot.

Installation

To install the package, type this command in R: ``` r install.packages("ggpointdensity")

Alternatively, you can install the latest

development version from GitHub:

if (!requireNamespace("devtools", quietly = TRUE)) install.packages("devtools") devtools::install_github("LKremer/ggpointdensity") ```

Motivation

There are several ways to visualize data points on a 2D coordinate system: If you have lots of data points on top of each other, geom_point() fails to give you an estimate of how many points are overlapping. geom_density2d() and geom_bin2d() solve this issue, but they make it impossible to investigate individual outlier points, which may be of interest.

geom_pointdensity() aims to solve this problem by combining the best of both worlds: individual points are colored by the number of neighboring points. This allows you to see the overall distribution, as well as individual points.

Demo

Generate some toy data and visualize it with geom_pointdensity(): ``` r library(ggplot2) library(dplyr) library(viridis) library(ggpointdensity)

dat <- bind_rows( tibble(x = rnorm(7000, sd = 1), y = rnorm(7000, sd = 10), group = "foo"), tibble(x = rnorm(3000, mean = 1, sd = .5), y = rnorm(3000, mean = 7, sd = 5), group = "bar"))

ggplot(data = dat, mapping = aes(x = x, y = y)) + geompointdensity() + scalecolor_viridis() ```

Each point is colored according to the number of neighboring points. The distance threshold to consider two points as neighbors (smoothing bandwidth) can be adjusted with the adjust argument, where adjust = 0.5 means use half of the default bandwidth. ``` r ggplot(data = dat, mapping = aes(x = x, y = y)) + geompointdensity(adjust = .1) + scalecolor_viridis()

ggplot(data = dat, mapping = aes(x = x, y = y)) + geompointdensity(adjust = 4) + scalecolorviridis() ``` <img src="man/figures/pointdensityadj.png" width="100%" />

Of course you can combine the geom with standard ggplot2 features such as facets...

``` r

Facetting by group

ggplot(data = dat, mapping = aes(x = x, y = y)) + geompointdensity() + scalecolorviridis() + facetwrap( ~ group) ```

... or point shape and size: r dat_subset <- sample_frac(dat, .1) # smaller data set ggplot(data = dat_subset, mapping = aes(x = x, y = y)) + geom_pointdensity(size = 3, shape = 17) + scale_color_viridis()

Zooming into the axis works as well, keep in mind that xlim() and ylim() change the density since they remove data points. It may be better to use coord_cartesian() instead.

``` r ggplot(data = dat, mapping = aes(x = x, y = y)) + geompointdensity() + scalecolor_viridis() + xlim(c(-1, 3)) + ylim(c(-5, 15))

ggplot(data = dat, mapping = aes(x = x, y = y)) + geompointdensity() + scalecolorviridis() + coordcartesian(xlim = c(-1, 3), ylim = c(-5, 15)) ```

Advanced usage

You can re-use or modify the density estimates using ggplot2's after_stat() function.

For instance, let's say you want to plot the density estimates on a relative instead of an absolute scale, i.e. scaled from 0 to 1. Of course this can be achieved by dividing the absolute density values by the maximum, but how do you access the density estimates on R code? The short answer is to use after_stat(density) inside an aesthetics mapping like so:

r ggplot(data = dat, aes(x = x, y = y, color = after_stat(density / max(density)))) + geom_pointdensity(size = .3) + scale_color_viridis() + labs(color = "relative\ndensity")

For a more in-depth explanation on after_stat(), check out the relevant ggplot documentation.

Since plotting the relative density is a common use-case, we provide a little shortcut. Instead of the solution above you can simply use after_stat(ndensity). This is especially useful when facetting data, since sometimes you want to inspect the point density separately for each facet:

r ggplot(data = dat, aes( x = x, y = y, color = after_stat(ndensity))) + geom_pointdensity( size = .25) + scale_color_viridis() + facet_wrap( ~ group) + labs(color = "relative\ndensity")

Even though the foo data group is not as dense as bar overall, this plot uses the whole color scale between 0 and 1 in both facets.

Lastly, you can use after_stat() to affect other plot aesthetics such as point size:

r ggplot(data = dat, aes(x = x, y = y, size = after_stat(1 / density ^ 1.8))) + geom_pointdensity(adjust = .2) + scale_color_viridis() + scale_size_continuous(range = c(.001, 3))

Here the point size is proportional to 1 / density ^ 1.8.

Authors

Lukas PM Kremer (@LPMKremer) and Simon Anders (@sandersm), 2019

Owner

  • Name: Lukas PM Kremer
  • Login: LKremer
  • Kind: user
  • Location: Heidelberg, Germany

PostDoc in Heidelberg. Omics, Bioinformatics & Stem Cells.

GitHub Events

Total
  • Release event: 1
  • Watch event: 25
  • Delete event: 1
  • Issue comment event: 1
  • Push event: 15
  • Pull request event: 2
  • Fork event: 4
  • Create event: 1
Last Year
  • Release event: 1
  • Watch event: 25
  • Delete event: 1
  • Issue comment event: 1
  • Push event: 15
  • Pull request event: 2
  • Fork event: 4
  • Create event: 1

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 57
  • Total Committers: 7
  • Avg Commits per committer: 8.143
  • Development Distribution Score (DDS): 0.211
Past Year
  • Commits: 21
  • Committers: 2
  • Avg Commits per committer: 10.5
  • Development Distribution Score (DDS): 0.048
Top Committers
Name Email Commits
LKremer l****r@w****e 45
Benjamin Reisman b****n@v****u 4
const-ae a****5@g****m 3
Jooa c****e@j****z 2
nathaneastwood n****d@i****m 1
Jan Gleixner j****r@g****m 1
lk385684 l****r@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 18
  • Total pull requests: 7
  • Average time to close issues: 5 months
  • Average time to close pull requests: 3 months
  • Total issue authors: 17
  • Total pull request authors: 6
  • Average comments per issue: 2.83
  • Average comments per pull request: 1.14
  • Merged pull requests: 6
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: 1 minute
  • Issue authors: 0
  • Pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • frederikziebell (2)
  • Okinur (1)
  • bkenm (1)
  • Mchicken1988 (1)
  • DarwinAwardWinner (1)
  • seasmith (1)
  • const-ae (1)
  • MxNl (1)
  • SONG-MAN (1)
  • ecalfee (1)
  • bjreisman (1)
  • Alanocallaghan (1)
  • shuckle16 (1)
  • zeqiandu (1)
  • Bisaloo (1)
Pull Request Authors
  • jan-glx (3)
  • LKremer (2)
  • lysogeny (1)
  • nathaneastwood (1)
  • bjreisman (1)
  • const-ae (1)
Top Labels
Issue Labels
enhancement (5) help wanted (1) good first issue (1) documentation (1)
Pull Request Labels

Packages

  • Total packages: 4
  • Total downloads:
    • cran 2,784 last-month
  • Total docker downloads: 1,743
  • Total dependent packages: 1
    (may contain duplicates)
  • Total dependent repositories: 13
    (may contain duplicates)
  • Total versions: 5
  • Total maintainers: 1
proxy.golang.org: github.com/lkremer/ggpointdensity
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.5%
Average: 5.7%
Dependent repos count: 5.9%
Last synced: 6 months ago
proxy.golang.org: github.com/LKremer/ggpointdensity
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.5%
Average: 5.7%
Dependent repos count: 5.9%
Last synced: 6 months ago
cran.r-project.org: ggpointdensity

A Cross Between a 2D Density Plot and a Scatter Plot

  • Versions: 2
  • Dependent Packages: 1
  • Dependent Repositories: 12
  • Downloads: 2,784 Last month
  • Docker Downloads: 1,743
Rankings
Stargazers count: 1.0%
Forks count: 3.3%
Dependent repos count: 8.3%
Average: 10.5%
Downloads: 11.5%
Dependent packages count: 18.1%
Docker downloads count: 21.0%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: r-ggpointdensity
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 1
Rankings
Stargazers count: 20.4%
Dependent repos count: 24.3%
Average: 32.7%
Forks count: 34.7%
Dependent packages count: 51.6%
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.2 depends
  • ggplot2 * imports
  • dplyr * suggests
  • viridis * suggests