Skip to content

Instantly share code, notes, and snippets.

@GuangchuangYu
Created April 23, 2012 08:37
Show Gist options
  • Save GuangchuangYu/2469605 to your computer and use it in GitHub Desktop.
Save GuangchuangYu/2469605 to your computer and use it in GitHub Desktop.
quantile quantile plot
## http://ygc.name/2011/08/02/q-q-plots/
qqplot <- function(y, distribution=qnorm) {
x <- distribution(ppoints(y))
plot(x, sort(y),
xlab="Theoretical Quantiles",
ylab="Sample Quantiles",
main="Normal Q-Q Plot"
)
lines(y,y)
}
qqplot2 <- function(y, distribution=qnorm) {
require(ggplot2)
x <- distribution(ppoints(y))
d <- data.frame(x=x, y=sort(y))
p <- ggplot(d, aes(x=x, y=y)) +
geom_point() +
geom_line(aes(x=x, y=x)) +
opts(title="Normal Q-Q Plot") +
xlab("Theoretical Quantiles") +
ylab("Sample Quantiles")
return(p)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment