[R] adding statistical output to a plot
dunner
ross.dunne at tcd.ie
Sat May 29 14:11:02 CEST 2010
Thanks to both of you,
I used the below code instead, which has been cleaned and pruned a little.
It produces a trellis of qq plots with the proper annotations as per Minitab
from a dataframe passed to mtab.matrix(). However, I can't get individual
variable names (these are column names in the passed dataframe) to annotate
the plots. Perhaps "apply" simply doesn't deal with the colname and I have
to try a completely different method? Or will apply pass enough information
to the included function (mtab.norm) to allow me to annotate the plot?
Again, I'm probably missing something banal and wholly obvious.
mtab.norm<-function(x){
library(nortest)
library(lattice)
x<-as.numeric(x)
x<-as.vector(x)
plot.ht<-4.6
plot.wd<-4.6
pt.ht=plot.ht/7
txt.sz<-(plot.ht/5)
qqnorm(x, pch=16, cex=pt.ht, col="darkorange", xlab=paste(colnames(x)),
ylab='', main='')
qqline(x, col="black", lty=2)
grid(col = "darkgrey", lty=2)
st.x<-shapiro.test(x)
mtext(paste("Shapiro-Wilks", "\n p =",signif(st.x$p.value,digits=4),"\n W
=",signif(st.x$statistic,digits=4)), line=1, cex=txt.sz, adj=0)
adt.x<-ad.test(x)
mtext(paste("Anderson-Darling", "\n p =",signif(adt.x$p.value,digits=4), "\n
W =", signif(adt.x$statistic,digits=4)), line=1, cex=txt.sz, adj=1)}
mtab.matrix<-function(z){
pdf(file=paste(colnames(z)[1],".pdf"), paper="a4r", width=0, height=0)
par(mfcol=c(3,3), mar=c(5.1,4.1,5.1,2.1))
par(bg="white")
apply(z, 2, mtab.norm)
dev.off()}
Thanks again for all your help. I am obviously a relative beginner, but an
enthusiast!
Dr. Ross Dunne,
HRB Clinical Research Fellow,
Dept. of Psychiatry, Trinity College Dublin.
--
View this message in context: http://r.789695.n4.nabble.com/adding-statistical-output-to-a-plot-tp2235565p2235629.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list