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

Incorrect shading / colors #44

Closed
jeroen opened this issue May 28, 2020 · 6 comments
Closed

Incorrect shading / colors #44

jeroen opened this issue May 28, 2020 · 6 comments

Comments

@jeroen
Copy link
Member

jeroen commented May 28, 2020

A user reported that the colors and shading in ragg is off. Here is a minimal example:

library(tidyverse)
library(ragg)

# generate data
group.a <- tibble(values = rnorm(n = 1000, mean = 0, sd = .3),
                  group = "group.a")
group.b <- tibble(values = rnorm(n = 1000, mean = 0, sd = .2),
                  group = "group.b")
group.c <- tibble(values = rnorm(n = 1000, mean = 0, sd = .1),
                  group = "group.c")
combined <- full_join(group.a, group.b)
combined = full_join(combined, group.c)

makeplot <- function(){
  ggplot() +
    scale_x_continuous(limits = c(-1, 1), breaks = c(-1, -.5, 0, .5 , 1)) +
    stat_density(data = combined, aes(x = values, y = factor(group), fill = group, alpha =  stat(density)), geom = "raster", position = "identity") +
    scale_fill_manual(values = c("#BF1E2E" , "#E6C949" , "#2AB9C1")) +
    scale_alpha_continuous(range = c(0.005, 1)) +
    geom_point(data = combined, aes(x = 0, y = group), size = 5, shape = 21, colour = "black", fill = "grey 95")
}


png(filename = "cairo.png", width = 1080, height = 720, res = 144)
makeplot()
dev.off()

agg_png(filename = "ragg.png", width = 1080, height = 720, res = 144)
makeplot()
dev.off()

Base / Cairo

cairo

Ragg

ragg

@thomasp85
Copy link
Member

Is this with the latest release? There were some fixes to premultiplication of input raster in that which looks like it could be the root cause of this...

@jeroen
Copy link
Member Author

jeroen commented May 28, 2020

Yes with the latest release.

@thomasp85
Copy link
Member

Yeah, I can reproduce. Something funky is going on when the raster is converted to the AGG colour space

@jeroen
Copy link
Member Author

jeroen commented May 28, 2020

Maybe alpha channel?

@thomasp85
Copy link
Member

I'm almost certain that the premultiplication is not getting performed correctly, so the blending gets messed up

@thomasp85
Copy link
Member

phew 😅 that was thankfully just a 12-character fix (after some hours of source code reading)

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