I have the following example plot: enter image description here

Created via:

p <- ggplot(test_data, aes(displ, cty,color=multi)) + geom_point()+ stat_smooth(method = "lm", fill = NA)
p + facet_grid(vars(drv), vars(cyl))

My question is:

I just want to compare the created lm models to see if they are significantly different from one another. For example, I would like to compare the green line from the first column & first row to the pink line from column 2 * row 2 (5,f).


closed as off-topic by Michael Chernick, gung Aug 13 at 17:54

  • This question does not appear to be about statistics within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Please add a reproducible example for people to work with. $\endgroup$ – gung Aug 13 at 17:54
  • $\begingroup$ I'm voting to close this question as off-topic because it is about how to use R without a reproducible example. $\endgroup$ – gung Aug 13 at 17:54

Welcome to Cross Validated!

I'll start with that I'm not 100% certain I understand the question. It may be that you are going about this in reverse. I would suggest you start out with fitting your data to your model (lm) and then using graphical methods to explore your fits. You can do this with ggplot.

Unfortunately, it is not possible to extract the information about the fits from ggplot. However, if you do the lm regression outside of ggplot you will get the same information.

Also, I notice that you did not specify a formula in geom_smooth, so I think it will default to y~x. If this is what you want, then perhaps you would be best to start out with a model such as

fit = lm(Yvals ~ Xvals + ColorVals + Xvals:ColorVals, data=all_sum)

I would suggest exploring the examples in the documentation. This blog post gives a nice function you can use to plot the results of a given fit with many useful annotations. Also, this question sounds a bit similar to yours and does have an accepted answer.

I hope this helps!


Not the answer you're looking for? Browse other questions tagged or ask your own question.