I've created a scatterplot of the relationship between variables x and y1, but I also want to add a fitted line showcasing the relationship between variables x and y2 on the same graph.
I decided to combine the data to make it easier, as follows:
data1 <- data %>%
group_by(var) %>%
summarize(x = n(), y1 = mean(y1_var), y2 = mean(y2_var))
I hope this isn't too confusing. I don't know how to actually make the plot. I've been trying anything, with my latest attempt being:
data1 %>%
ggplot(aes(x = x, y = y1)) +
geom_point(color = "blue") +
geom_point(x = x, y = y2, color = "yellow") +
geom_smooth(method = "lm", se = FALSE)
I know I don't have a good understanding of ggplot2, but just to show sort of where I'm at.
Any help would be appreciated!