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
Lattice: Add abline to Single Value qqmath() Plot
7 messages · David L Carlson, Rich Shepard, ilai
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.
On Tue, 15 May 2012, David L Carlson wrote:
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, Thank you. I do need to learn more about panels in lattice. Much appreciated, Rich
On Tue, 15 May 2012, David L Carlson wrote:
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,
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
On Tue, May 15, 2012 at 4:19 PM, Rich Shepard <rshepard at appl-ecosys.com> wrote:
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')".
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:
?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'),
Right here the " ' " is on the wrong side of " ) " causing the error:
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
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.
On Tue, 15 May 2012, ilai 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:
ilai, Good to know! Thank you.
pdf('ag_norm.pdf') qqmath(~ Ag | factor(basin), data = surfchem.cast,
main = 'Silver (Untransformed'),
Right here the " ' " is on the wrong side of " ) " causing the error:
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
On Tue, 15 May 2012, ilai 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:
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