I'm trying to make a norm qqplot using plotly.js with the value obtained in R.
I can get the y-axis values.
m <- lm(Sepal.Length ~ Sepal.Width + Petal.Width, data=iris)
plot(m, which=2) #this plot is what I want to make using plotly
std.resi <- rstandard(m) # y-axis values
But, there's problem. I don't know how to get the x-axis values.
please advise me on this matter. thank you.
The x-axis contains the quantiles of a Gaussian distribution.
So, imagining that you have N points, you can obtain the values of you x-axis via:
a <- (1:N+1)/(N+1) #get N equally spaced values between 0 and 1
a <- a[c(-(N+1))] #remove value at 1
quant <- qnorm(a) #obtain gaussian quantiles
Hope it helps!
std.resi
N <- length(std.resi)
a_2 <- 1:(N+1) / (N+1)
a_2<- a_2[c(-(N+1))]
std.resi.sort <- sort(std.resi)
quant <- qnorm(a_2)
plot(quant, std.resi.sort)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.