Skip to content

Conversation

@teunbrand
Copy link
Collaborator

This PR aims to fix #6429.

Instead of improving the 'no shared levels' warning as implied by the issue, this PR separately warns about the simulatenous use of an aesthetic in mapping and as a fixed aesthetic.

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point(aes(size = cty), size = 12)
#> Warning in geom_point(aes(size = cty), size = 12): The size aesthetic is defined twice: once in `mapping` and once as a static
#> aesthetic.
#> ℹ The static aesthetic overrules the mapped aesthetic.

We only do this when this occurs within a layer. If local fixed aesthetics contradict the global mapping, this is not a warning:

# silent
p <- ggplot(mpg, aes(displ, hwy, size = cty)) +
  geom_point(size = 12)

Created on 2025-11-12 with reprex v2.1.1

This is because people can intentionally deviate the local aesthetic from global mappings to exempt that aesthetic from inherit.aes. In contrast, I don't think you can intentially have contradicting aesthetics in a single layer.

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

Successfully merging this pull request may close these issues.

scale_manual warning "no shared levels" could be improved

1 participant