in R Language by
Scatter plot with fitted values in R Language

► Click here to show 1 Answer

0 votes

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)

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
Learn More with Madanswer

Related questions

0 votes
asked Nov 14, 2019 in R Language by MBarbieri