r - ggplot2 包中的标准化残差 x 理论分位数图

标签 r ggplot2

我正在尝试使用 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

而且我无法更改 xlabylab 名称。我该如何解决?

最佳答案

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

enter image description here

关于r - ggplot2 包中的标准化残差 x 理论分位数图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39808015/

相关文章:

r - 在数据框中使用日期时间对象

r - 在 kableExtra 中使用 cell_spec 时,使表中的 NA 值只是空白单元格

css - Shiny 的井板宽度

r - 在ggplot2中绘制每个第二个数据点

r - 为 geom_bar 图创建垂直颜色渐变

r - 使用字符串作为dplyr中的过滤器?

r - 将值从特定行更改为 R 中的数据框中

r - 使用 geom_segment 按因素分组数据

r - ggplot 图例关键颜色和项目

r - ggplot 更改某些图例项的大小