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

Increase the default nbin of colourbar #3521

Conversation

yutannihilation
Copy link
Member

@yutannihilation yutannihilation commented Sep 7, 2019

Fix #3508

This PR increases the default nbin of colourbar to 300.

I did some experiments, and nbin = 300 seems sufficient to me (on Windows device). For performance, nbin = 300 is might be slower a bit, but I think it's acceptable.

# current master branch
devtools::load_all("~/repo/R/ggplot2")
#> Loading ggplot2

p <- ggplot(base::data.frame(x = 1:3)) +
  geom_point(aes(x, x, colour = x))

get_colourbar <- function(nbin) {
  p <- p + scale_color_gradient(
    paste0("nbin =\n", nbin),
    guide = guide_colorbar(barheight = grid::unit(1, "npc") - grid::unit(4, "line"),nbin = nbin)
  )
  data <- ggplot_build(p)
  g <- ggplot_gtable(data)
  g$grobs[[15]]
}

gridExtra::grid.arrange(
  get_colourbar(20),
  get_colourbar(40),
  get_colourbar(60),
  get_colourbar(80),
  get_colourbar(100),
  get_colourbar(150),
  get_colourbar(200),
  get_colourbar(250),
  get_colourbar(300),
  get_colourbar(400),
  get_colourbar(500),
  nrow = 1
)

res <- bench::mark(
  `nbin = 020` = grid.draw(get_colourbar(20)),
  `nbin = 100` = grid.draw(get_colourbar(100)),
  `nbin = 200` = grid.draw(get_colourbar(200)),
  `nbin = 300` = grid.draw(get_colourbar(300)),
  `nbin = 500` = grid.draw(get_colourbar(500)),
  check = FALSE,
  min_iterations = 30
)

autoplot(res)
#> Loading required namespace: tidyr

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thomasp85 thomasp85 added this to the ggplot2 3.3.0 milestone Oct 1, 2019
@yutannihilation
Copy link
Member Author

Thanks.

@yutannihilation yutannihilation merged commit 115c396 into tidyverse:master Oct 13, 2019
@yutannihilation yutannihilation deleted the fix/issue-3508-default-nbin-of-colourbar branch October 13, 2019 06:35
@lock
Copy link

lock bot commented Apr 15, 2020

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: enable expand arguments for continuous color and fill scales.
2 participants