# Qqnorm and qqplot

**URL:** <https://discourse.julialang.org/t/qqnorm-and-qqplot/6118>\
**Category:** New to Julia\
**Created:** [September 27, 2017, 3:34pm UTC](https://discourse.julialang.org/t/qqnorm-and-qqplot/6118 "2017-09-27T15:34:14Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![harven](https://avatars.discourse-cdn.com/v4/letter/h/3da27b/32.png) [@harven](https://discourse.julialang.org/u/harven)\
**Post date:** [September 27, 2017, 3:34pm UTC](https://discourse.julialang.org/t/qqnorm-and-qqplot/6118/1 "2017-09-27T15:34:15Z")

</div>

Is there an equivalent to R qqnorm and qqplot functions in some julia package?

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 27, 2017, 8:53pm UTC](https://discourse.julialang.org/t/qqnorm-and-qqplot/6118/2 "2017-09-27T20:53:03Z")

</div>

There’s a gist here for how to do it with Gadfly [https://gist.github.com/kleinschmidt/7ce8cec988a84ce73ba2](https://gist.github.com/kleinschmidt/7ce8cec988a84ce73ba2)

It would be fairly easy to make a recipe for this for StatPlots as well - we should definitely have that.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 27, 2017, 9:09pm UTC](https://discourse.julialang.org/t/qqnorm-and-qqplot/6118/3 "2017-09-27T21:09:37Z")

</div>

This should work with Plots:

```julia

using Distributions, RecipesBase

@recipe function f(h::QQPair)
    seriestype --> :scatter
    h.qx, h.qy
end

@userplot QQPlot
@recipe f(h::QQPlot) = qqbuild(h.args[1], h.args[2])
    
@userplot QQNorm
@recipe f(h::QQNorm) = qqbuild(Normal(), h.args[1])

```

Use like this:

```julia
x = rand(Normal(), 100)
y = rand(Cauchy(), 100)

using Plots
qqplot(x,y)
qqnorm(y)

```

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 28, 2017, 6:45am UTC](https://discourse.julialang.org/t/qqnorm-and-qqplot/6118/4 "2017-09-28T06:45:47Z")

</div>

And now there’s a PR on StatPlots:  
[https://github.com/JuliaPlots/StatPlots.jl/pull/99](https://github.com/JuliaPlots/StatPlots.jl/pull/99)  
@harven there’s a request for comment on the pull request, if you like.

---

<div class="post-metadata">

**Author:** ![harven](https://avatars.discourse-cdn.com/v4/letter/h/3da27b/32.png) [@harven](https://discourse.julialang.org/u/harven)\
**Post date:** [September 28, 2017, 3:44pm UTC](https://discourse.julialang.org/t/qqnorm-and-qqplot/6118/5 "2017-09-28T15:44:05Z")

</div>

That’s great, thank you! I will have a look at the RFC soon.

---

<div class="post-metadata">

**Author:** ![Robin\_De\_Schepper](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robin_de_schepper/32/8048_2.png) [@Robin\_De\_Schepper](https://discourse.julialang.org/u/Robin_De_Schepper)\
**Post date:** [April 19, 2019, 11:44am UTC](https://discourse.julialang.org/t/qqnorm-and-qqplot/6118/6 "2019-04-19T11:44:10Z")

</div>

What’s the current status? How can we use it?

---

<div class="post-metadata">

**Author:** ![alejandromerchan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alejandromerchan/32/10500_2.png) [@alejandromerchan](https://discourse.julialang.org/u/alejandromerchan)\
**Post date:** [April 19, 2019, 4:38pm UTC](https://discourse.julialang.org/t/qqnorm-and-qqplot/6118/7 "2019-04-19T16:38:06Z")

</div>

The package StatsPlots has the qq plot function available.

---

<div class="post-metadata">

**Author:** ![Gunter\_Faes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunter_faes/32/12580_2.png) [@Gunter\_Faes](https://discourse.julialang.org/u/Gunter_Faes)\
**Post date:** [April 21, 2019, 8:22am UTC](https://discourse.julialang.org/t/qqnorm-and-qqplot/6118/8 "2019-04-21T08:22:04Z")

</div>

Possibly so:

```julia
# Estimate distribution parameters:
mw = mean(fix_Acid)
StdAbw = std(fix_Acid)
# Create QQ plot:
qqplot(Normal(mw, StdAbw), fix_Acid, title = "QQ-Plot gebundene Säuren", ylabel = "Gehalt geb. Säuren")

```

 ![QQ-Plot_1](https://global.discourse-cdn.com/julialang/original/3X/5/b/5b9ef7837567182d4b5cd7525a21828d9bad622a.jpeg)

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [November 15, 2019, 1:32pm UTC](https://discourse.julialang.org/t/qqnorm-and-qqplot/6118/9 "2019-11-15T13:32:43Z")

</div>

Manual way with Plots:

```julia
using Distributions, Plots
function myqqplot(obs,F⁰,title)
    nobs=length(obs)
    sort!(obs)
    quantiles⁰ = [quantile(F⁰,i/nobs) for i in 1:nobs]
    # Note that only n-1 points may be plotted, as quantile(F⁰,1) may be inf
    plot(quantiles⁰, obs, seriestype=:scatter, xlabel="Theoretical Quantiles", ylabel = "Sample Quantiles", title=title, label="" )
    plot!(obs,obs,label="")
end
obs = rand(Normal(0,1),1000)
F⁰=Normal(0,1)
myqqplot(obs,F⁰,"Normal QQ-plot ")

```

![qqplot](https://global.discourse-cdn.com/julialang/original/3X/c/5/c5e97748e4ecb45410431df9ca9e2b4448082a06.png)

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [November 15, 2019, 3:27pm UTC](https://discourse.julialang.org/t/qqnorm-and-qqplot/6118/10 "2019-11-15T15:27:38Z")

</div>

And an updated [link for Gadfly.](http://gadflyjl.org/dev/gallery/statistics/#%5BStat.qq%5D(@ref)-1)

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [November 15, 2019, 4:11pm UTC](https://discourse.julialang.org/t/qqnorm-and-qqplot/6118/11 "2019-11-15T16:11:35Z")

</div>

This is inbuilt in StatsPlots for more than a year: [https://github.com/JuliaPlots/StatsPlots.jl#quantile-quantile-plots](https://github.com/JuliaPlots/StatsPlots.jl#quantile-quantile-plots)
