Skip to content

Instantly share code, notes, and snippets.

@mauricioaniche
Last active October 4, 2016 22:51
Show Gist options
  • Save mauricioaniche/946823537fd7e6ed225c88ab9f7e5004 to your computer and use it in GitHub Desktop.
Save mauricioaniche/946823537fd7e6ed225c88ab9f7e5004 to your computer and use it in GitHub Desktop.
Quantile plot in R
# distr <- your data
# logscale <- T if you want it to be at log-scale
qp <- function(distr, logscale) {
x <- c()
y <- c()
qt <- 0.01
for(i in 1:99) {
x <- append(x, qt)
newY <- quantile(distr, c(qt))[1]
if(logscale) newY <- log(newY)
y <- append(y, newY)
qt <- qt + 0.01
}
print(y)
p1<-quantile(distr, c(0.5))[1]
if(logscale) p1 <- log(p1)
p2<-quantile(distr, c(0.99))[1]
if(logscale) p2 <- log(p2)+1
plot(c(0,0.5,1),c(1,p1,p2), type="n", xlab="", ylab="", cex.axis=1)
points(x,y, type="l", col="red", lwd=5)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment