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

Gradient as colourbar #5548

Merged
merged 11 commits into from
Dec 14, 2023
Merged

Gradient as colourbar #5548

merged 11 commits into from
Dec 14, 2023

Conversation

teunbrand
Copy link
Collaborator

@teunbrand teunbrand commented Nov 29, 2023

This PR aims to fix #5547.

Briefly, it adds a new argument to guide_colourbar(): display, which can be set to "gradient' to display the bar as a gradient.

In some more detail; since the raster argument was implemented as a boolean, I'd thought it best to deprecate it and use display as an enumeration instead. Possible values for display are "raster", which is the same as current raster = TRUE, "rectangles", equivalent to raster = FALSE and "gradient", the new option.

When display = "gradient", the nbins argument is used for the number of colours set in the gradient, rather than actual bins. As such, we don't need to account for the half bin-size offset for the label placement. The nbins number can be a lot less in gradient displays compared to raster/rectangle displays. As such, nbins defaults to 15 for gradients.

Prior to R 4.1.0, {grid} hadn't implemented linearGradient(), so for older R versions it throws an error saying that linearGradient is unavailabe in the R version.

No visual test has been included due to {vdiffr} not supporting gradients.

Small demo:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

ggplot(mpg, aes(displ, hwy)) +
  geom_point(aes(colour = cty)) +
  guides(colour = guide_colourbar(display = "gradient"))

Created on 2023-11-29 with reprex v2.0.2

@teunbrand

This comment was marked as resolved.

R/guide-colorbar.R Outdated Show resolved Hide resolved
R/guide-colorbar.R Outdated Show resolved Hide resolved
@thomasp85 thomasp85 added this to the ggplot2 3.5.0 milestone Dec 14, 2023
teunbrand and others added 4 commits December 14, 2023 12:10
Merge branch 'main' into colourbar_gradient

# Conflicts:
#	R/backports.R
#	R/guide-colorbar.R
#	R/guide-colorsteps.R
#	man/guide_colourbar.Rd
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

Merge branch 'main' into colourbar_gradient

# Conflicts:
#	R/guide-colorbar.R
#	man/guide_colourbar.Rd
@teunbrand
Copy link
Collaborator Author

Thanks for the review!

@teunbrand teunbrand merged commit dd7887f into tidyverse:main Dec 14, 2023
12 checks passed
@teunbrand teunbrand deleted the colourbar_gradient branch December 14, 2023 15:27
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

Successfully merging this pull request may close these issues.

Feature request: colourbar as gradients
2 participants