Categories

Nov 14, 2019 in R Language

Q: Scatter plot with fitted values in R Language

1 Answer

Nov 14, 2019

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
Click here to read more about Loan/Mortgage
Click here to read more about Insurance

Related questions

Madanswer
Nov 14, 2019 in R Language
Jul 28, 2019 in R Language
Nov 14, 2019 in R Language
...