qqnorm and qqline in ggplot2

后端 未结 8 1734
隐瞒了意图╮
隐瞒了意图╮ 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 07:10

    Why not the following?

    Given some vector, say,

    myresiduals <- rnorm(100) ^ 2
    
    ggplot(data=as.data.frame(qqnorm( myresiduals , plot=F)), mapping=aes(x=x, y=y)) + 
        geom_point() + geom_smooth(method="lm", se=FALSE)
    

    But it seems strange that we have to use a traditional graphics function to prop up ggplot2.

    Can't we get the same effect somehow by starting with the vector for which we want the quantile plot and then applying the appropriate "stat" and "geom" functions in ggplot2?

    Does Hadley Wickham monitor these posts? Maybe he can show us a better way.

提交回复
热议问题