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

differing behaviour using "color = NA" in Linux and Windows #3129

Closed
JayVii opened this Issue Feb 11, 2019 · 5 comments

Comments

Projects
None yet
3 participants
@JayVii
Copy link

JayVii commented Feb 11, 2019

During a project, I used following snippet to draw a completely transparent hexbin map:

  plot <- ggplot(data, aes(x = lon, y = lat, z = marks)) +
      coord_fixed(ratio = width/height) +
      stat_summary_hex(binwidth = c(width * scale, height * scale),
                       color = NA, show.legend = FALSE, size = border_width)
      scale_fill_gradient(low = "#00000000", high = "#00000000") +
      theme_void()

Note the color argument in stat_summary_hexbin() is set to NA. This worked fine on Linux and produced a transparent hexbin layer. However on Windows the same script produced a completely black hexbin layer (eventhough scale_fill_gradient() is set to transparent colors). This persisted when trying to use Cairo to render the output graphic under Windows.

Explicitly specifying the plot to be transparent via fill = transparent in stat_summary_hexbin() fixed the issue on Windows.

The point still stands, that NA as filling color seems to be treated differently across different OSes, if I interpreted this issue correctly.

@batpigandme

This comment has been minimized.

Copy link
Member

batpigandme commented Feb 11, 2019

Could you please turn this into a self-contained reprex (short for minimal reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page.

You can install reprex by running (you may already have it, though, if you have the tidyverse package installed):

install.packages("reprex")

Thanks

@clauswilke

This comment has been minimized.

Copy link
Member

clauswilke commented Feb 11, 2019

Gradients with transparency were only recently introduced in the scales package. My hunch is that the scales package on the windows system is too old. Could you check which version you have there? Start a new R session, and then enter:

library(scales)
sessionInfo()

Then post the output here.

@JayVii

This comment has been minimized.

Copy link
Author

JayVii commented Feb 11, 2019

@batpigandme

Could you please turn this into a self-contained reprex (short for minimal reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

reprex seems not very helpful in this case, as the above code-snipped is part of a much more complicated function and a rather large dataset. But here is a simplified version as produced with reprex():

library(ggplot2)
data <- data.frame(lon = c(1, 2, 3), lat = c(1, 2, 3), marks = c(0, 1, 0))
myplot <- ggplot(data, aes(x = lon, y = lat, z = marks)) +
    stat_summary_hex(color = NA, show.legend = FALSE) +
    scale_fill_gradient(low = "#00000000", high = "#00000000") +
    theme_void()
myplot

Created on 2019-02-11 by the reprex package (v0.2.1)

@clauswilke

Gradients with transparency were only recently introduced in the scales package. My hunch is that the scales package on the windows system is too old. Could you check which version you have there?

Indeed, scales is at 1.0.0 on the Linux machine and 0.5.0 on the Windows box. I only checked ggplot2 and hexbin versions before. Thanks for the hint!

@clauswilke

This comment has been minimized.

Copy link
Member

clauswilke commented Feb 11, 2019

Fixed in current release of scales.

@clauswilke clauswilke closed this Feb 11, 2019

@batpigandme

This comment has been minimized.

Copy link
Member

batpigandme commented Feb 11, 2019

But here is a simplified version as produced with reprex()

That's the very goal of a reprex, to make a minimal version of the issue you're encountering — the "minimal" part just isn't in the portmanteau. Glad to hear it's fixed in scales!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment