log probability plot in R?

后端 未结 2 1971
甜味超标
甜味超标 2021-01-06 15:11

Does anyone know how to create log probability plot like this one in R where the x-axis is probability and y-axis is in log-scale. I read and downloaded the package heR.Misc

2条回答
  •  一个人的身影
    2021-01-06 16:08

    Here is an example using base R, simplified a bit from this post: (https://stat.ethz.ch/pipermail/r-help/2004-February/045370.html).

    ## Make some data
    y <- rnorm(n=175, mean=100, sd=75)
    y <- sort(y)
    pct <- 1:length(y)/(length(y)+1)
    
    ## For x ticks
    probs <- c(0.0001, 0.001, 0.01, 0.1, 0.3, 0.5, 0.7,
               0.9, 0.99, 0.999, 0.9999)
    x.vals <- qnorm(probs)     
    
    ## Plotting area
    xs <- c(-4, 4)
    ys <- seq(-2,4)
    par(xaxs="i", yaxs="i")
    plot(NA, NA, xlim=c(xs[1], xs[2]), ylim=c(min(ys), max(ys)),
         axes=FALSE, xlab=NA, ylab=NA)
    
    ## X Axis
    axis(side=1, at=x.vals, labels=FALSE, tck=-0.01)
    
    text(x=x.vals, y=rep(min(ys)-0.35, length(x.vals)),
         labels=probs*100, xpd=TRUE, srt=325, font=2)
    
    ## Y Axis
    axis(side=2, at=ys, labels=FALSE)
    text(y=ys, x=rep(xs[1]-.08, length(ys)),
         labels= as.character(10^ys), xpd = NA, font=2,
         pos=2)
    
    for (i in ys){
        axis(side=2, at=log10(seq(2,9))+ i,
             labels=NA, tck = -0.01)
    }
    
    ## Grid lines and box
    abline(h=ys, col="grey80", lty=2)
    abline(v=qnorm(probs), col="grey80", lty=2)
    box()
    
    ## Plot Data
    lines(x=qnorm(pct), y=log10(y), col="blue")
    

提交回复
热议问题