1
$\begingroup$

enter image description here

enter image description here

How do you plot many regression lines in a plot? This concerns the textbook question from "Forecasting: Principles and Practice". A dataset concerns winning times of Olympic running events. Categories include year, length (distance), sex (gender). The question askes to make a regression line for each plot to see the average rate of change for each event.

I could brute force this question but I want to find an efficient way to make multiple regression lines in a single plot. Is this possible?

$\endgroup$

1 Answer 1

1
$\begingroup$

I don't know the dataset but normally this would be done much more easily using the color dimension, something like this:

ggplot(aes(x=Year, y=Time, color=Length))
  +geom_point()
  +geom_smooth(method='lm')

Note that you may have to convert Length to a factor first, or use color=as.factor(Length) in aes.

$\endgroup$
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.