Discussion:
[R] Lattice: Add abline to Single Value qqmath() Plot
Rich Shepard
2012-05-15 17:30:59 UTC
Permalink
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
David L Carlson
2012-05-15 18:18:29 UTC
Permalink
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
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
project.org] On Behalf Of Rich Shepard
Sent: Tuesday, May 15, 2012 12:31 PM
To: r-help at r-project.org
Subject: [R] Lattice: Add abline to Single Value qqmath() Plot
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
______________________________________________
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.
Rich Shepard
2012-05-15 18:26:55 UTC
Permalink
Post by David L Carlson
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
qqmath(~ rnorm(100),
panel = function(x, ...) {
panel.qqmathline(x, ...)
panel.qqmath(x, ...)
})
David,

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

Much appreciated,

Rich
Rich Shepard
2012-05-15 22:19:30 UTC
Permalink
Post by David L Carlson
qqmath(~ rnorm(100),
panel = function(x, ...) {
panel.qqmathline(x, ...)
panel.qqmath(x, ...)
})
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,
Post by David L Carlson
source('metals.R')
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
--
Richard B. Shepard, Ph.D. | Integrity - Credibility - Innovation
Applied Ecosystem Services, Inc. | Helping Ensure Our Clients' Futures
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
ilai
2012-05-15 23:37:36 UTC
Permalink
Post by Rich Shepard
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')".
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,
Post by Rich Shepard
?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'),
Error in source("metals.R") : metals.R:4:83: unexpected ','
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
Post by Rich Shepard
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
--
Richard B. Shepard, Ph.D. ? ? ? ? ?| ? Integrity - Credibility - Innovation
Applied Ecosystem Services, Inc. ? | ? ?Helping Ensure Our Clients' Futures
<http://www.appl-ecosys.com> ? ? Voice: 503-667-4517 ? ? ?Fax: 503-667-8863
______________________________________________
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.
Rich Shepard
2012-05-16 00:36:57 UTC
Permalink
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.
ilai,

Good to know! Thank you.
pdf('ag_norm.pdf') qqmath(~ Ag | factor(basin), data = surfchem.cast,
main = 'Silver (Untransformed'),
Oops! I saw what I expected to see, not what was there. Again, thanks.

Rich
--
Richard B. Shepard, Ph.D. | Integrity - Credibility - Innovation
Applied Ecosystem Services, Inc. | Helping Ensure Our Clients' Futures
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
Rich Shepard
2012-05-17 00:24:06 UTC
Permalink
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.
ilai,

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

Rich
--
Richard B. Shepard, Ph.D. | Integrity - Credibility - Innovation
Applied Ecosystem Services, Inc. | Helping Ensure Our Clients' Futures
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
Loading...