To set alpha value just for the line you should replace stat_smooth()
with geom_line()
and then inside the geom_line()
use the same arguments as in stat_smooth()
and additionally add stat="smooth"
.
ggplot(df, aes(x=x, y=value, color=variable)) +
geom_point(size=2) +
geom_line(stat="smooth",method = "lm", formula = y ~ 0 + I(1/x) + I((x-1)/x),
size = 1.5,
linetype ="dashed",
alpha = 0.5)