Regression line in legend should be thinner

Viewed 149

I am ploting points with regression line. Size of points is in a variable. Regression line in legend is plotted with different width than in my graph.

df = data.frame( x=1:20, y=(1:20)^ 2 , t=20:1 )
ggplot(df,aes(x=x,y=y,size=t)) + 
  geom_point() +
  geom_smooth(method='loess')

I get this graph. Look legend is not real. graphic with legend error

Regression line in legend should be thinner. How can I fix this?

1 Answers

Simple! Just add a size parameter. You can choose any number you like, I think .5 is a nice crisp line

library( ggplot2 )
df = data.frame( x=1:20, y=(1:20)^ 2 , t=20:1 )
ggplot(df,aes(x=x,y=y,size=t)) + 
  geom_point() +
  geom_smooth(method='loess', size=.5)

enter image description here

Related