Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overlapping points are semi-transparent #25

Open
igordot opened this issue Jul 16, 2024 · 2 comments
Open

overlapping points are semi-transparent #25

igordot opened this issue Jul 16, 2024 · 2 comments

Comments

@igordot
Copy link

igordot commented Jul 16, 2024

I am having some issues with the alpha parameter.

This is the ggplot2 version:

ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point(size = 10, alpha = 1)

image

And the scattermore version:

ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_scattermore(pointsize = 15, alpha = 1, pixels = c(300, 300))

image

As you can see, when the points are overlapping, they are semi-transparent if they are different colors.

I am using scattermore 1.2 and ggplot2 3.5.1.

@exaexa
Copy link
Owner

exaexa commented Jul 16, 2024

Hello,
this is in fact the correct behavior; scattermore defaults to a blend mode that avoids overplotting. You might notice the points are actually not transparent, it's just that the color is a weighted average of all colors of points that occupy that given pixel.

The difference here is that ggplot and base R use the usual "layered" RGBA blending, which "hides" previous points behind new ones (just as the blue one behind the green ones in your case). Scattermore uses RGBWT by default, which always blends all layers equally. It's certainly not very "nice" for a few huge points like in your example here, but it helps a lot for huge amounts of little points (which is the target use-case of scattermore). E.g., for single-cell data vis, this makes sure you don't accidentally miss a small cluster in your picture.

If you want to have some points hidden explicitly, the best way is to use the lower-level API (e.g. this and this) to create RGBA layers and blend them in your preferred order. We don't have dedicated "frontend" functionality for this because it's a completely different use-case.

Hope this explanation helps :] I'll leave this open for now; maybe I'll find a bit of time to add the low-level-API solution to the docs at some point.

@igordot
Copy link
Author

igordot commented Jul 16, 2024

Thank you for the clarification. Would you be able to provide an example of how to remove the blending?

I was just using big points to have a very clear example. For little points, I agree blending can be helpful, but not necessarily. For example, if you have red and blue points, purple areas are mixed and blending makes sense. If you have red, blue, and purple points, then purple areas can be red+blue, red+blue+purple, or just purple, so blending introduces ambiguity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants