Skip to content

guide_legend's effectiveness depends on order of aesthetic mappings #6571

@william-l-barcelona-fr

Description

@william-l-barcelona-fr

I found a possible problem with guide_legend()s effectiveness within guides() depending on the order of aesthetic mappings in the ggplot() call.

I expected that nrow = 2 in the guide_legend() call for shape in guides would have an effect, but it doesn't seem to be working. It does work if I switch shape to be mapped before color though.

Here is the code to reproduce the bug:

library(ggplot2)
  
ggplot(
  mtcars,
  aes(x = wt, y = mpg, color = as.factor(cyl), shape = as.factor(cyl))
) +
  geom_point() +
  guides(shape = guide_legend(nrow = 2))

ggplot(
  mtcars,
  aes(x = wt, y = mpg, shape = as.factor(cyl), color = as.factor(cyl))
) +
  geom_point() +
  guides(shape = guide_legend(nrow = 2))
Image Image

Should the order of the aesthetic mappings matter here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions