In more detail
The slope is Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² and the intercept is ȳ − slope × x̄. For the points (1,2), (2,4), (3,5), (4,4), (5,5) the line is y = 0.6x + 2.2. The correlation coefficient r measures how well the line fits, not whether one variable causes the other.