qqline connects the first and third quartiles. How do I draw a line between different quantiles (ie 30% and 70%)?

前端 未结 3 865
南笙
南笙 2021-01-20 14:14

I have a qqnorm plot of a data set with 1000+ points. I want to draw a line between two quantiles at a time (say 30% and 70%) just as qqline does with 25% and 75%, but with

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-20 15:18

    EDIT:

    The information below is valid for R (and stats package) version 2.15.1 - apparently later versions will incorporate the built-in capability of plotting arbitrary quantiles.


    qqline seems to be hard-coded to plot the .25 and .75 quantiles. But if you don't mind creating your own function, something like this might do:

    myQqplot <- function(data, probs){
      qqnorm(data)
      theQuants <- quantile(data, probs = probs)
      lm1 <- lm(theQuants~qnorm(probs))
      abline(lm1)
      invisible()
    }
    
    myQqplot(diffbp, c(.5,.99))  
    

    enter image description here

    There's no check to make sure that you supply only two quantiles to the probs argument, but you could add it if you want.

提交回复
热议问题