我正在尝试使用 ggplot2
包绘制“理论分位数”X“标准化残差”图。
我有一个用于此图的 lm()
模型
library(ggplot2)
model<-lm(mpg~cyl+disp+hp+drat+wt, data=mtcars)
p2<-ggplot(model, aes(qqnorm(.stdresid)[[1]], .stdresid))+geom_point(na.rm = TRUE)
p2<-p2+geom_abline(aes(qqline(.stdresid)))+xlab("Theoretical Quantiles")+ylab("Standardized Residuals")
p2<-p2+ggtitle("Normal Q-Q")+theme_bw()
p2
我在这里创建的代码 https://rpubs.com/therimalaya/43190绘制图,但返回错误
Error: Aesthetics must be either length 1 or the same as the data (3110): x
而且我无法更改 xlab
或 ylab
名称。我该如何解决?
最佳答案
model<-lm(mpg~cyl+disp+hp+drat+wt, data=mtcars)
library(ggplot2)
p2 <- ggplot(model, aes(qqnorm(.stdresid)[[1]], .stdresid))+geom_point(na.rm = TRUE)
p2 <- p2+geom_abline()+xlab("Theoretical Quantiles")+ylab("Standardized Residuals")
p2 <- p2+ggtitle("Normal Q-Q")+theme_bw()
p2
关于r - ggplot2 包中的标准化残差 x 理论分位数图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39808015/