Skip to content

Instantly share code, notes, and snippets.

@meren
Created January 8, 2013 16:18
Show Gist options
  • Save meren/4485081 to your computer and use it in GitHub Desktop.
Save meren/4485081 to your computer and use it in GitHub Desktop.
a substitute for qqplot and qqline.
#####################################################################################
# Q-Q plot in ggplot2
# taken from http://stackoverflow.com/questions/4357031/qqnorm-and-qqline-in-ggplot2
#####################################################################################
require(ggplot2)
vec <- Hg$AMT # whateer
y <- quantile(vec[!is.na(vec)], c(0.25, 0.75))
x <- qnorm(c(0.25, 0.75))
slope <- diff(y)/diff(x)
int <- y[1L] - slope * x[1L]
d <- data.frame(resids = vec)
ggplot(d, aes(sample = resids)) + stat_qq() + geom_abline(slope = slope, intercept = int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment