Robert Long
Robert Long

Reputation: 6802

Preventing a second legend

I have a ggplot, which also displays a legend:

ggplot(dt.m, aes(x=pct.on.OAC.cont,y=Number.of.Practices, fill=Age.Group)) +
    geom_bar(stat="identity",position=position_dodge())

When I add another line, I also get a second legend:

geom_smooth(aes(x=pct.on.OAC.cont,y=Number.of.Practices, colour=Age.Group), se=F, alpha=0.5)

How can I prevent the second legend from displaying ?

Upvotes: 10

Views: 2850

Answers (1)

Sven Hohenstein
Sven Hohenstein

Reputation: 81683

Use show_legend = FALSE in geom_smooth:

geom_smooth(aes(x=pct.on.OAC.cont,y=Number.of.Practices, colour=Age.Group),
            se=F, alpha=0.5, show_legend = FALSE)

This suppresses drawing a legend.

Upvotes: 16

Related Questions