qqnorm and qqline in ggplot2

后端 未结 8 1755
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 06:37

Say have a linear model LM that I want a qq plot of the residuals. Normally I would use the R base graphics:

qqnorm(residuals(LM), ylab=\"Residuals\")
qqline         


        
8条回答
  •  误落风尘
    2020-12-04 06:57

    You could steal a page from the old-timers who did this stuff with normal probability paper. A careful look at a ggplot()+stat_qq() graphic suggests that a reference line can be added with geom_abline(), like this

    df <- data.frame( y=rpois(100, 4) )
    
    ggplot(df, aes(sample=y)) +
      stat_qq() +
      geom_abline(intercept=mean(df$y), slope = sd(df$y))
    

提交回复
热议问题