You can add another level of information to the graph. You can plot the fitted value of a linear regression.
my_graph <- ggplot(mtcars, aes(x = log(mpg), y = log(drat))) +
geom_point(aes(color = factor(gear))) +
stat_smooth(method = "lm",
col = "#C42126",
se = FALSE,
size = 1)
my_graph
Code Explanation
- graph: You store your graph into the variable graph. It is helpful for further use or avoid too complex line of codes
- The argument stat_smooth() controls for the smoothing method
- method = "lm": Linear regression
- col = "#C42126": Code for the red color of the line
- se = FALSE: Don't display the standard error
- size = 1: the size of the line is 1