1

I want to extract the linear models given by the ggplot2. Is there a better way to extract these models instead of re-running the individual model separately?

Below is a reproducible code. However, note that Ecdat package is quite big.

library(ggplot2);library(Ecdat)
data('Housing') # from Ecdat
ggplot(Housing, aes(lotsize, price, color = airco, fill = airco)) +
  geom_point() +
  geom_smooth(method = 'lm') +
  ggtitle('Price (lotsize)') + facet_grid( . ~ airco, margins = T) + theme_classic()

Below is the visual output from ggplot. You may notice that we have 3 different models below. I would like to extract the 3 models for further analysis instead of rerunning them with lm().

Thanks!

enter image description here

Afiq Johari
  • 1,372
  • 1
  • 15
  • 28
  • It seems this is [not currently possible](https://github.com/STAT545-UBC/Discussion/issues/491) and appears to be by design. I however think there should be a way to get "backend" and extract the models. See what hadley had to say back [then](https://stackoverflow.com/a/2667343/10323798). – NelsonGon Oct 01 '19 at 06:11
  • 1
    Hi @NelsonGon, thanks for the link, I guess from Hadley comment, it's not something they would work on. It's ok then, I just rerun the model separately to get the coeffs. Should I close this question or leave it as it is? – Afiq Johari Oct 01 '19 at 06:22
  • 1
    I think you should leave the question as is. Chances are someone might have thought of a way to do it or one may come across it and think it would be something cool to implement. – NelsonGon Oct 01 '19 at 06:24

0 Answers0