LKremer/ggpointdensity

geom_jitter?

shuckle16 opened this issue ยท 4 comments

Hi, thanks for the work on this very useful package!

This might be a dumb thought, but I was wondering if it would be possible to incorporate jitter'ed points (probably through geom_jitter) as an option. I'm not sure if it would be better to calculate the density before or after jittering, too.

Thanks again!

It's definitely possible and super easy to implement, but I'm not sure when you would want to have both jitter and points colored by density. Ideally you don't need to jitter at all anymore when using ggpointdensity. But if you give me a good use case I'll happily implement it ๐Ÿ‘

Good point, I'm not sure the use case I was thinking of is that important. The other day I ran across some data like this and thought it might be cool to jitter the points a little.

Either way, thanks for your response!

library(tidyverse)
library(ggpointdensity)

matrix(c(rep(1:3,50), rep(1:2,10), rep(2:3, 15)), ncol = 2) %>% 
  as.data.frame() %>% 
  ggplot(aes(x = V1, y = V2)) + geom_pointdensity()

image

Hi @shuckle16 ,

After revisiting this issue I realized that it's pretty straightforward to get the intended result with ggplot2's position argument:

library(tidyverse)
library(ggpointdensity)

matrix(c(rep(1:3,50), rep(1:2,10), rep(2:3, 15)), ncol = 2) %>% 
  as.data.frame() %>% 
  ggplot(aes(x = V1, y = V2)) +
  geom_pointdensity(position = position_jitter(width=.1, height=.1))

I hope this helps!

Good point! thank you