Skip to content

Default aesthetics for stats can create unexpected legend titles #2406

Closed
@datalorax

Description

@datalorax

I've run into some unexpected behavior when using geom_density_2d.

If I run

library(ggplot2)
ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  geom_smooth(aes(color = drv)) 

The legend title corresponds to the variable name (drv).
screen shot 2018-01-17 at 11 55 02 am

But if I add a geom_density_2d layer that I want plotted under the smooths, the legend title changes to "colour".

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  geom_density2d() +
  geom_smooth(aes(color = drv)) 

screen shot 2018-01-17 at 11 57 24 am

I'm aware that I could change this manually with guides(color = guide_legend(title = "drv")) and so it's not that big of a deal, but it did seem odd to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorscales 🐍

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions