Skip to content

Lattice: Add abline to Single Value qqmath() Plot

7 messages · David L Carlson, Rich Shepard, ilai

#
The data are not normally distributed when untransformed and I'm trying
various transformations to see if any would be appropriate to use. The
lattice book (fig. 3.10) shows a 2-sample Q-Q plot with an abline but the
code for the figure does not include the line.

   I'd appreciate a pointer to a reference on how to add an abline to a
one-sample qqmath() plot in lattice.

Rich
#
Take a look at section 3.3.6 qqmath
http://www.his.sunderland.ac.uk/~cs0her/Statistics/UsingLatticeGraphicsInR.h
tm

You need to create a panel function. See sections 2.5.2 and 2.5.3 in the
second chapter of the Lattice book
(http://dsarkar.fhcrc.org/lattice/book/chapter2.pdf) available on Deepayan
Sarkar's webpage.

This is a simple example modified from the example in the lattice package
manual:

qqmath(~ rnorm(100), 
  panel = function(x, ...) {
    panel.qqmathline(x, ...)
    panel.qqmath(x, ...)
  })


----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
#
On Tue, 15 May 2012, David L Carlson wrote:

            
David,

   Thank you. I do need to learn more about panels in lattice.

Much appreciated,

Rich
#
On Tue, 15 May 2012, David L Carlson wrote:

            
David,

   I have 130 plots to produce (30 chemicals un-transformed and three
transformations). The R console insists that I retype each of the 6 lines
(adding a prepanel.qqmathline line) each time. Makes more sense to put all
the commands in a script that I can run within R using "source('metals.R')".

   However, R appears to not see that the first line does not terminate the
command and the following lines are continuations. The source is,

pdf('ag_norm.pdf')
qqmath(~ Ag | factor(basin), data = surfchem.cast, main = 'Silver (Untransformed'),
   prepanel = prepanel.qqmathline,
   panel = function(x, ...) {
     panel.qqmathline(x, ...)
     panel.qqmath(x, ...)
   })
dev.off()

and R returns,
Error in source("metals.R") : metals.R:4:83: unexpected ','
3: pdf('ag_norm.pdf')
4: qqmath(~ Ag | factor(basin), data = surfchem.cast, main = 'Silver (Untransformed'),

with a caret under the last ')'.

   What syntax error did I commit in the call to qqmath() above?

Rich
#
On Tue, May 15, 2012 at 4:19 PM, Rich Shepard <rshepard at appl-ecosys.com> wrote:
Apologies in advance if I misinterpret " R console insists that I
retype ..." but actually makes more sense (than sourcing a script) to
use the group argument (see the last example in ?qqmath) as in 4
groups in each of 30 panels, or allow.multiple=T, outer=T if you
really want separate panels for each transformation. Also can use
layout=c(1,1,120) if you need each in a separate page  - or say
c(3,2,20) for 20 pages of 6 panels each, etc. Regarding your script,
there is a syntax error:
Right here the " ' " is on the wrong side of " ) " causing the error:
because the plot is "done" with ) with unexpected "," following. You want
...main = ' Silver (Untransformed) ' ,

Personally I find using spaces whenever possible helps me avoid this
type of syntax error (which is the most frustrating...)

Cheers
#
On Tue, 15 May 2012, ilai wrote:

            
ilai,

   Good to know! Thank you.
Oops! I saw what I expected to see, not what was there. Again, thanks.

Rich
#
On Tue, 15 May 2012, ilai wrote:

            
ilai,

   Grouping doesn't do what's needed, but the split() function does. Thanks
for pointing me in that direction.

Rich