Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Standardized residuals x Theoretical Quantiles plot in ggplot2 package

Tags:

r

ggplot2

I'm trying to do a plot "Theoretical Quantiles"X "Standardized Residuals" using ggplot2 package.

I have a lm() model that I used to this plot

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

This code that I founded here https://rpubs.com/therimalaya/43190 make the plot, but returns an error

Error: Aesthetics must be either length 1 or the same as the data (3110): x

and I can't change the xlab or ylab names. How I can solve it?

like image 535
Roland Avatar asked Apr 10 '26 01:04

Roland


1 Answers

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

like image 154
Hack-R Avatar answered Apr 11 '26 14:04

Hack-R