[R] Help With Custom QQ Plot

Adam Carr adamlcarr at yahoo.com
Tue Dec 29 01:21:41 CET 2009


Hello Dennis:

Thanks for the reply and for your help. I apologize for the errant TUS in the data. Your statement about the quantiles of the data belonging to the vertical axis is correct of course and it helped me realize an error of mine: the quantiles plotted as vertical reference lines are from a fitted distribution based on the data. I have included an example of the plot in the attachment.

I ran the code you sent and it is a very good start. I simply need to understand how to include the fitted normal data as the x-axis or as a set of vertical reference points.

About the distinct data points: you are correct about this as well. I realize that there are ties in the data. This is pretty typical for these kinds of material property measurements. I meant, but did not state clearly, that I wanted to plot the data as points and not as a line.

Thanks again for your help.

Adam 



________________________________
From: Dennis Murphy <djmuser at gmail.com>
To: Adam Carr <adamlcarr at yahoo.com>
Sent: Mon, December 28, 2009 4:12:54 PM
Subject: Re: [R] Help With Custom QQ Plot

Hi: 

This isn't precisely what you want, but it's a start. Both base graphics and lattice plot the normal
quantiles on the horizontal axis and the observed values on the vertical axis, so it's the transpose
of what you want.

After reading in your data (I had to get rid of the stray TUS two-thirds of the way down the file)
into an object I called qqdata, I did the following:

qqq <- quantile(qqdata, c(.01, .1, .2, .5, .8, .9, .99))
qqnorm(qqdata)
qqline(qqdata)
abline(h = qqq, lty = 'dotted')

This is all using base graphics. Use xlab, ylab and main in the qqnorm() call to adjust the labels.

The author of lattice, Deepayan Sarkar, has published a book called Lattice, available from 
Springer. If you were to use it, the appropriate function would be qqmath, whose default
theoretical distribution is the normal.

 If you insist on having the theoretical quantiles on the
vertical axis, then in R you would likely have to use ggplot2, but you would have to build up
the plot from its elements.


On Mon, Dec 28, 2009 at 6:49 AM, Adam Carr <adamlcarr at yahoo.com> wrote:

Good Morning:
>
>I have attached a text file with one hundred thirty six observations. I would like to create a qq plot with the following features:
>
>1. Observed values on the y-axis.
>
Check. 

2. Normal approximation line on the plot.
>
Check. 

3. X-axis with vertical reference lines at the following percentiles of the data: 1, 10, 20, 50, 80, 90 and 99.
>
If your data are on the Y-axis, the percentiles of the *data* would also have to be on the y-axis.
This is shown on the plot. Check. 

4. Data appearing on the plot as distinct points.
>
qqnorm does what it can, but you have numerous tied values in your data. How do you expect them to
be plotted as distinct points? You can jitter them, but that will have some impact on the corresponding
quantiles and the position of the fitted 'normal approximation line' .


>I assume that qqmath (lattice) is the best approach to this although I have not been able to sort out the proper syntax to yield the plot I'm after. I understand how to determine the quantiles of the data, and I can use qqmath() to generate a plot which has the observed values on the y-axis, and the plot is based on a normal distribution, but beyond this I'm struggling.
>
>I do not have the R Graphics text by  or Visualizing Data by Bill Cleveland but I have several other R books (Crawley, Ugarte et al, Braun/Murdoch, Rizzo, etc) but coverage of the lattice package seems light.
>
>I very much appreciate any help that could be offered.
>
>Thank you.
>
>Adam
>
>
>     
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
>
>



      
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Example Plot for Recreation in R.pdf
Type: application/pdf
Size: 23720 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091228/ce1e1aa1/attachment-0002.pdf>


More information about the R-help mailing list