tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.39k stars 2k forks source link

`guide_colorsteps()` can't set the `position` #5930

Open Andtise opened 1 month ago

Andtise commented 1 month ago

In my use of the newer version of ggplot2 (version3.5.1), I found that I can't set the position for guide_colorstep individually, but only through the global theme's legend.position.

I'm not sure if this is intentional or not, but I think it doesn't follow the logic of guides as a whole. Here's a simple example:

library(ggplot2)

# position not working of guide_colorsteps
p1 <- ggplot(mpg, aes(displ, hwy, colour = cty)) +
  geom_point() +
  guides(color=guide_colorsteps(position = "bottom"))

# position working of guide_colorbar
p2 <- ggplot(mpg, aes(displ, hwy, colour = cty)) +
  geom_point() +
  guides(color=guide_colorbar(position = "bottom"))

# global theme’s legend.position setting
p3 <- ggplot(mpg, aes(displ, hwy, colour = cty)) +
  geom_point() +
  guides(color=guide_colorsteps()) +
  theme(legend.position = "bottom")

patchwork::wrap_plots(p1, p2, p3)

bug

teunbrand commented 1 month ago

You're right, thanks for catching this!