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

Images in png, transparent background plotted in black. #2

Open
Airpino opened this issue Feb 22, 2023 · 1 comment
Open

Images in png, transparent background plotted in black. #2

Airpino opened this issue Feb 22, 2023 · 1 comment

Comments

@Airpino
Copy link

Airpino commented Feb 22, 2023

Dear, I have a set of images in png with transparent backgroung generated via:
ggsave(filename = "image1.png",plot = my_ggplot,width = 4, height = 4,dpi=150, bg='transparent')

Now when, I use ggimg the transparent background is plotted as balck. I used a code like this
ggplot(df[1:10,],aes(x=.data[[names(df)[1]]], y=.data[[names(df)[2]]]))+ geom_point_img(aes( x = .data[[names(df)[1]]], y = .data[[names(df)[2]]], img = "image1.png" ), size = 1)+ theme_minimal()

There is a way to tell to goem_point_img to cosider transparent background?

@billy34
Copy link

billy34 commented Sep 1, 2023

By looking at code we can see a hint in comment on unexported function fix_img_dims in funs.R.

# Takes an input image file (either an array or matrix), along with a scalar
# alpha value, and returns an array that will always have four channels; set
# alpha to a negative number to avoid overwriting any present opacity values

By setting alpha parameter of geom_point_img or geom_rect_img to a negative value seems to solve the problem.

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