Skip to content

guide_custom does not adhere to legend order #6195

Closed
@julianbarg

Description

@julianbarg

Even though guide_custom accepts an order argument, it always appears as the last legend in the sidebar.

Here is a reproducible example. Notice that you can use the order argument to reorder the color and shape legend but not change the position of the custom legend:

library(tidyverse)

df <- tribble(
  ~x, ~y, ~color, ~shape, 
  1, 2, "grey", 1,
  2, 2, "red", 2
) %>%
  mutate(shape = as.factor(shape))
circle <- grid::circleGrob()
custom <- guide_custom(circle, title = "My circle", order = 1,
                       width = unit(2, "cm"), height = unit(2, "cm"))
color_legend <- guide_legend(order = 3)
shape_legend <- guide_legend(order = 2)

ggplot(df, aes(x, y, color = color, shape = shape)) +
  geom_point() + 
  guides(color = color_legend, 
         shape = shape_legend,
         custom = custom)

R version 4.4.2 (2024-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Debian GNU/Linux trixie/sid
ggplot2_3.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorguides 📏

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions