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

Guide colorsteps creates an ugly, large NA box #3876

Closed
clauswilke opened this issue Mar 9, 2020 · 6 comments · Fixed by #3999
Closed

Guide colorsteps creates an ugly, large NA box #3876

clauswilke opened this issue Mar 9, 2020 · 6 comments · Fixed by #3999

Comments

@clauswilke
Copy link
Member

clauswilke commented Mar 9, 2020

Technically another issue against my PR #3864. I made this figure yesterday and I thought the guide looks ugly. Why is the box representing NA so large? Should NA be shown at all by default? Should it maybe be shown with a little gap? Is this correct at all?

library(ggplot2)

set.seed(4393)
dsmall <- diamonds[sample(nrow(diamonds), 1000), ]

ggplot(dsmall, aes(x, y)) +
  geom_density_2d_filled(aes(fill = after_stat(level_high))) +
  scale_fill_viridis_c(guide = "colorsteps")

Created on 2020-03-09 by the reprex package (v0.3.0)

@clauswilke
Copy link
Member Author

For comparison, this is what it looks like with guide = "legend".

library(ggplot2)

set.seed(4393)
dsmall <- diamonds[sample(nrow(diamonds), 1000), ]

ggplot(dsmall, aes(x, y)) +
  geom_density_2d_filled(aes(fill = after_stat(level_high))) +
  scale_fill_viridis_c(guide = "legend")

Created on 2020-03-09 by the reprex package (v0.3.0)

@thomasp85
Copy link
Member

I’m pretty sure this is due to the recent fix to make NA work with binning. In my point of view, NA shouldn’t be shown in the legend at all. I’ll look into a fix

@thomasp85 thomasp85 added this to the ggplot2 3.3.1 milestone Mar 10, 2020
@yutannihilation
Copy link
Member

Hmm, this might be my oversight, but the CRAN version seems to behave the same... I'm a bit confused. Is it intended to use *_viridis_c(), not *_viridis_b(), for binned scales?

library(tidyverse)

sessioninfo::package_info("ggplot2", dependencies = FALSE)
#>  package * version date       lib source        
#>  ggplot2 * 3.3.0   2020-03-05 [1] CRAN (R 3.6.3)
#> 
#> [1] /home/yutani/R/x86_64-pc-linux-gnu-library/3.6
#> [2] /usr/lib/R/library

data(airquality)

airQ <- filter_all(airquality, ~!is.na(.))

ggplot(airQ, aes(x = Solar.R, y = Temp)) +
  stat_density_2d(aes(fill = after_stat(level)), geom = "polygon") +
  scale_fill_viridis_c(guide = "coloursteps")

Created on 2020-03-10 by the reprex package (v0.3.0)

library(ggplot2)

set.seed(4393)
dsmall <- diamonds[sample(nrow(diamonds), 1000), ]

ggplot(dsmall, aes(x, y)) +
  geom_density_2d_filled(aes(fill = after_stat(level_high))) +
  scale_fill_viridis_b(guide = "colorsteps")

Created on 2020-03-10 by the reprex package (v0.3.0)

@clauswilke
Copy link
Member Author

It looks to me like with the binned scale, we're binning twice, once to make the contours and once to assign the colors. Notice how we have more contour bands than colors.

library(ggplot2)

set.seed(4393)
dsmall <- diamonds[sample(nrow(diamonds), 1000), ]

ggplot(dsmall, aes(x, y)) +
  geom_density_2d_filled(aes(fill = after_stat(level_high)), color = "white") +
  scale_fill_viridis_b(guide = "colorsteps")

Created on 2020-03-10 by the reprex package (v0.3.0)

@yutannihilation
Copy link
Member

Thanks, I see.

@thomasp85
Copy link
Member

Yeah. There are some stats that provide the binning themselves because they need access to the unbinned data. These should not be mixed with the binning scales

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

Successfully merging a pull request may close this issue.

3 participants