yosukesabai
yosukesabai

Reputation: 6244

ggplot2 not showing line in geom_point's legend

I want to create a scatter plot with regression line, while using size aesthetics for one of attribute. I realized that the legend now have overlaid symbol for fitted line and I want to remove that, keeping only the legend for size. How can I do that?

> library(ggplot2)
> ggplot(mtcars, aes(wt, mpg, size=cyl)) + geom_point()

This much gives this picture, which is good: no smooth line

Now having smooth line on top, and then this blue "line" is what i want to get rid of, or at least make all thin like the one in the plot is.

> ggplot(mtcars, aes(wt, mpg, size=cyl)) + geom_point() + stat_smooth()

with smooth line

Thanks!

Upvotes: 1

Views: 1707

Answers (2)

chrischi
chrischi

Reputation: 185

The most recent documentation {ggplot2} version 2.2.1 uses legend.show= NA

ggplot(mtcars, aes(wt, mpg, size=cyl)) + geom_point() + stat_smooth(show.legend = F)

Upvotes: 0

ilya
ilya

Reputation: 3164

use legend=FALSE option

ggplot(mtcars, aes(wt, mpg, size=cyl)) + geom_point() + stat_smooth(legend = FALSE)

Upvotes: 4

Related Questions