Skip to content

Feature request: Is it possible to use legend.justification.* adjust the legend position directly in guide_colorbar #6263

Closed
@Breeze-Hu

Description

@Breeze-Hu

Happy New Year in advance!

The update in version 3.5 https://www.tidyverse.org/blog/2024/02/ggplot2-3-5-0-legends/#placement mentions the fine adjustment of the legend position, which can now be done in combination with guides and theme.

It was the expected result and worked out well:

library(ggplot2)

ggplot(mpg, aes(displ, hwy, shape = factor(cyl), colour = cty)) +
  geom_point()+
  guides(color = guide_colorbar(position = 'bottom'))+
  theme(legend.justification.bottom = 'left')

Image

Is it possible to do positional adjustments (top, bottom, left, right) in the guide in scale_*_* and guides in combination with the theme for the bottom-left position, etc.? Currently only adjusts to the bottom, but not to the right. legend.justification = 'left' or legend.justification.bottom = 'left' for both of the following does not work as expected:

ggplot(mpg, aes(displ, hwy, shape = factor(cyl), colour = cty)) +
  geom_point()+
  scale_color_continuous(
  guide =  guide_colorbar(position = 'bottom',
                        theme = theme(legend.justification.bottom = 'left')))
ggplot(mpg, aes(displ, hwy, shape = factor(cyl), colour = cty)) +
  geom_point()+
  guides(color = guide_colorbar(position = 'bottom',
                                theme =  theme(legend.justification.bottom = 'left')))
ggplot(mpg, aes(displ, hwy, shape = factor(cyl), colour = cty)) +
  geom_point()+
  scale_color_continuous(
    guide =  guide_colorbar(position = 'bottom',
                            theme = theme(legend.justification = 'left')))
ggplot(mpg, aes(displ, hwy, shape = factor(cyl), colour = cty)) +
  geom_point()+
  scale_color_continuous(
    guide =  guide_colorbar(position = 'bottom',
                            theme = theme(legend.justification = c(0,0))))

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions