All Projects → LKremer → Ggpointdensity

LKremer / Ggpointdensity

Licence: gpl-3.0
📈 📊 Introduces geom_pointdensity(): A Cross Between a Scatter Plot and a 2D Density Plot.

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to Ggpointdensity

Ggalt
🌎 Extra Coordinate Systems, Geoms, Statistical Transformations & Scales for 'ggplot2'
Stars: ✭ 561 (+96.15%)
Mutual labels:  ggplot2, ggplot-extension, rstats
Ggcats
The geom you always wished for adding cats to ggplot2
Stars: ✭ 34 (-88.11%)
Mutual labels:  ggplot2, ggplot-extension, rstats
Ggforce
Accelerating ggplot2
Stars: ✭ 640 (+123.78%)
Mutual labels:  ggplot2, ggplot-extension, rstats
Hrbrthemes
🔏 Opinionated, typographic-centric ggplot2 themes and theme components
Stars: ✭ 899 (+214.34%)
Mutual labels:  ggplot2, ggplot-extension, rstats
Econocharts
Microeconomics/macroeconomics charts in ggplot2
Stars: ✭ 161 (-43.71%)
Mutual labels:  ggplot2, ggplot-extension, rstats
Ggsignif
Easily add significance brackets to your ggplots
Stars: ✭ 322 (+12.59%)
Mutual labels:  ggplot2, ggplot-extension, rstats
Tidymv
Tidy Model Visualisation for Generalised Additive Models
Stars: ✭ 25 (-91.26%)
Mutual labels:  ggplot2, r-package, rstats
Ggextra
📊 Add marginal histograms to ggplot2, and more ggplot2 enhancements
Stars: ✭ 299 (+4.55%)
Mutual labels:  ggplot2, r-package, rstats
Patchwork
The Composer of ggplots
Stars: ✭ 2,002 (+600%)
Mutual labels:  ggplot2, ggplot-extension, rstats
Gganimate
A Grammar of Animated Graphics
Stars: ✭ 1,744 (+509.79%)
Mutual labels:  ggplot2, ggplot-extension, rstats
Ggbernie
A ggplot2 geom for adding Bernie Sanders to ggplot2
Stars: ✭ 96 (-66.43%)
Mutual labels:  ggplot2, ggplot-extension, rstats
Plotly
An interactive graphing library for R
Stars: ✭ 2,096 (+632.87%)
Mutual labels:  ggplot2, r-package, rstats
Calendr
Ready to print calendars with ggplot2
Stars: ✭ 161 (-43.71%)
Mutual labels:  ggplot2, ggplot-extension, rstats
cusumcharter
Easier CUSUM control charts. Returns simple CUSUM statistics, CUSUMs with control limit calculations, and function to generate faceted CUSUM Control Charts
Stars: ✭ 17 (-94.06%)
Mutual labels:  ggplot2, rstats, r-package
worrms
World Register of Marine Species R client
Stars: ✭ 13 (-95.45%)
Mutual labels:  rstats, r-package
schtools
Schloss Lab Tools for Reproducible Microbiome Research 💩
Stars: ✭ 22 (-92.31%)
Mutual labels:  rstats, r-package
jcolors
A set of color palettes I like (or can at least tolerate)
Stars: ✭ 24 (-91.61%)
Mutual labels:  ggplot2, r-package
rredlist
IUCN Red List API Client
Stars: ✭ 31 (-89.16%)
Mutual labels:  rstats, r-package
miner
R package for controlling Minecraft via API
Stars: ✭ 74 (-74.13%)
Mutual labels:  rstats, r-package
checkers
⛔ ARCHIVED ⛔ Automated checking of best practices for research compendia ✔️
Stars: ✭ 53 (-81.47%)
Mutual labels:  rstats, r-package

ggpointdensity

CRAN_Status_Badge Downloads

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

Installation

To install the package, type this command in 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.

Changelog

Added method argument and renamed the n_neighbor stat to density. The available options are method="auto", method="default" and method="kde2d". default is the regular n_neighbor calculation as in the CRAN package. kde2d uses 2D kernel density estimation to estimate the point density (credits to @slowkow). This method is slower for few points, but faster for many (ca. >20k) points. By default, method="auto" picks either kde2d or default depending on the number of points.

Demo

Generate some toy data and visualize it with geom_pointdensity():

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)) +
  geom_pointdensity() +
  scale_color_viridis()

Each point is colored according to the number of neighboring points. (Note: this here is the dev branch, where I decided to plot the density estimate instead of n_neighbors now.) 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.

ggplot(data = dat, mapping = aes(x = x, y = y)) +
  geom_pointdensity(adjust = .1) +
  scale_color_viridis()
 
ggplot(data = dat, mapping = aes(x = x, y = y)) +
  geom_pointdensity(adjust = 4) +
  scale_color_viridis()

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

# Facetting by group
ggplot(data = dat, mapping = aes(x = x, y = y)) +
  geom_pointdensity() +
  scale_color_viridis() +
  facet_wrap( ~ group)

... or point shape and size:

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.

ggplot(data = dat, mapping = aes(x = x, y = y)) +
  geom_pointdensity() +
  scale_color_viridis() +
  xlim(c(-1, 3)) + ylim(c(-5, 15))

ggplot(data = dat, mapping = aes(x = x, y = y)) +
  geom_pointdensity() +
  scale_color_viridis() +
  coord_cartesian(xlim = c(-1, 3), ylim = c(-5, 15))

Authors

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].