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

Continuous limits for discrete scales #6273

Merged
merged 9 commits into from
Jan 21, 2025

Conversation

teunbrand
Copy link
Collaborator

@teunbrand teunbrand commented Jan 7, 2025

This PR aims to fix #6259 and fix #4174.

Briefly, the discrete position scales get a new argument continuous.limits which controls what range is displayed.
It always acts as 'zoom limits', similar to limits set in the coord or continuous limits with oob = scales::oob_keep().

Reprex from #4174:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2
df <- data.frame(
  stringsAsFactors = FALSE,
  continent = c("europe","europe","europe",
                "europe","asia","asia","asia","south america"),
  country = c("AT", "DE", "DK", "ES", "PK", "IN", "TW", "BR"),
  value = c(10L, 15L, 20L, 25L, 17L, 17L, 13L, 5L)
)

p <- df |>
  ggplot() +
  geom_col(
    aes(y = country, x = value),
    orientation = "y"
  ) +
  facet_wrap(vars(continent), scales = "free_y")

p + scale_y_discrete(continuous.limits = c(1, 4))

Created on 2025-01-07 with reprex v2.1.1

@teunbrand
Copy link
Collaborator Author

I now also believe this would be needed for #3441 to make copies of discrete scales with immutable ranges.

@teunbrand

This comment was marked as resolved.

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

@teunbrand teunbrand merged commit 97edd62 into tidyverse:main Jan 21, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants