Skip to content

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #6020.

Briefly, it allows expand to take a length-4 logical vector for each of the positions (top, right, bottom, left).
Alternatively, one could use a named vector too.

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

# Showing logical vector
ggplot(mpg, aes(class)) +
  geom_bar() +
  coord_cartesian(expand = c(TRUE, TRUE, FALSE, TRUE))

# Showing named vector
ggplot(mpg, aes(y = class)) +
  geom_bar() +
  coord_cartesian(expand = c(left = FALSE))

Created on 2024-08-05 with reprex v2.1.1

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.

I like this idea

@@ -89,6 +89,7 @@ CoordFlip <- ggproto("CoordFlip", CoordCartesian,
},

setup_panel_params = function(self, scale_x, scale_y, params = list()) {
params$expand <- params$expand[c(2, 1, 4, 3)]
Copy link
Member

Choose a reason for hiding this comment

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

Not sure flipping the coord params is the logical solution here

Copy link
Collaborator Author

@teunbrand teunbrand Aug 26, 2024

Choose a reason for hiding this comment

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

In this PR, coord_flip(expand = c(left = FALSE)) removes the left expansion, which feels correct to me. I don't know how much this intuition holds, but I feel like coord_flip() swaps x/y, but not left/bottom and right/top.
I'm unsure whether there is a more logical solution available here.

@teunbrand teunbrand merged commit 7ce155b into tidyverse:main Aug 28, 2024
13 checks passed
@teunbrand teunbrand deleted the repurpose_expand branch August 28, 2024 07:24
teunbrand added a commit that referenced this pull request Sep 23, 2024
* fallback for numeric expand

* add test
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: alternate expand parameter
2 participants