I need to create multiple regression lines on a scatterplot that I made with ggplot2 that has two values, male and female, however I'm having a bit of trouble trying to set up the code. I created a scatterplot that shows two sets of data using the following code:
ggplot(LifeSatisfaction, aes(x=Country)) +
geom_point(aes(y = Life_Satisfaction_Female), color = "palevioletred2") +
geom_smooth(method = "lm", y = Life_Satisfaction_Female, col = "red") +
geom_point(aes(y = Life_Satisfaction_Male), color="steelblue") +
geom_smooth(method = "lm", y = Life_Satisfaction_Male, col = "blue") +
labs (title = "Life Satisfaction per Country", x = "Country", y = "Life Satisfaction Rating") + ylim(5, 8)
I tried using
geom_smooth ()
, however it doesn't seem to be working with multiple values.
Any and all help is appreciated!
Edit: just wanted to say that I'm very new to rstudio and coding in general so please explain in simple terms haha