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

Bug: where reversed global colour & fill aesthetic, and fixed colour in geom #411

Closed
davidhodge931 opened this issue Nov 10, 2023 · 3 comments

Comments

@davidhodge931
Copy link

davidhodge931 commented Nov 10, 2023

Not sure if this is fixable at ggplot2 or scales ends. So raised at both places
tidyverse/ggplot2#5531

In the latest DEV version of scales, there seems to be a bug where ggplot is not able to over-ride a reversed global colour aesthetic with a fixed colour in a subsequent layer. This same code works perfectly with the current CRAN version of scales. Whether I used the DEV or CRAN version of ggplot2 had no effect on this.

library(tidyverse)
#> Warning: package 'purrr' was built under R version 4.3.1
#> Warning: package 'dplyr' was built under R version 4.3.1
#> Warning: package 'forcats' was built under R version 4.3.2
#> Warning: package 'lubridate' was built under R version 4.3.1
library(patchwork)

palmerpenguins::penguins |>
  drop_na() |> 
  group_by(species) |>
  summarise(body_mass_g = mean(body_mass_g)) |>
  mutate(lower = body_mass_g * 0.95) |> 
  mutate(upper = body_mass_g * 1.2)|>
  ggplot(aes(x = body_mass_g,
         y = species,
         col = fct_rev(species),
         fill = fct_rev(species))) +
  geom_col(
    width = 0.75,
    alpha = 0.5
  ) +
  geom_errorbar(
    aes(xmin = lower, xmax = upper),
    colour = "black",
    width = 0.1
  )

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

@davidhodge931 davidhodge931 changed the title Bug where ggplot is not able to over-ride a reversed global colour aesthetic with a fixed colour in a subsequent geom layer Bug with reversed global colour aesthetic and fixed colour in later geom layer Nov 10, 2023
@davidhodge931 davidhodge931 changed the title Bug with reversed global colour aesthetic and fixed colour in later geom layer Bug with reversed global colour aesthetic and fixed colour in geom layer Nov 10, 2023
@davidhodge931 davidhodge931 changed the title Bug with reversed global colour aesthetic and fixed colour in geom layer Bug with reversed global colour aesthetic and fixed colour in geom Nov 10, 2023
@davidhodge931 davidhodge931 changed the title Bug with reversed global colour aesthetic and fixed colour in geom Bug with reversed global colour & fill aesthetic, and fixed colour in geom Nov 10, 2023
@teunbrand
Copy link
Contributor

A more minimal reprex for {scales}; training same data twice re-sorts levels.

library(scales)

fct <- factor(LETTERS[1:3], LETTERS[3:1])

r <- DiscreteRange$new()
r$train(fct)
r$range
#> [1] "C" "B" "A"

r$train(fct)
r$range
#> [1] "A" "B" "C"

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

@davidhodge931 davidhodge931 changed the title Bug with reversed global colour & fill aesthetic, and fixed colour in geom Bug: where reversed global colour & fill aesthetic, and fixed colour in geom Nov 25, 2023
@thomasp85
Copy link
Member

Fixed in dev

@davidhodge931
Copy link
Author

Awesome, thanks!

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

No branches or pull requests

3 participants