0

I have a linear regression across deciles of a variable (highly skewed) and I've plotted a line across the deciles to predict the outcome variability. The plot does give me a regression line across the deciles however I want to add median values of each decile on the X axis to better explain the distribution of my variable.

ggplotRegression <- function (fit) {

require(ggplot2)

ggplot(fit$model, aes_string(x = names(fit$model)[2], y = names(fit$model)[1])) + 
  geom_point() +
  stat_smooth(method = "lm", col = "red") +
  labs(title = paste("Adj R2 = ",signif(summary(fit)$adj.r.squared, 5),
                     "Intercept =",signif(fit$coef[[1]],5 ),
                     " Slope =",signif(fit$coef[[2]], 5),
                     " P =",signif(summary(fit)$coef[2,4], 5)))
}

ggplotRegression(lm(math_score ~ lead_decile, data=mkf1))

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Getting `Error in is.data.frame(data) : object 'mkf1' not found` – jay.sf Jul 11 '19 at 14:31
  • 1
    Welcome to Stackoverflow. please see [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). It would be helpful if you provide a minimal data set so that one can cut/paste and reproduce what you have done so far. – steveb Jul 11 '19 at 14:40
  • 1
    Please provide a reproducible example, using a standard dataset. Type `library(help = 'datasets') to see if any of these are similar enough to illustrate your question. – JonMinton Jul 11 '19 at 14:41

0 Answers0