[R] pairs: adjusting margins and labeling axes

Duncan Mackay dulcalma at bigpond.com
Wed Jul 20 03:43:02 CEST 2016


Hi
Will doing in lattice suite

>From  https://stat.ethz.ch/pipermail/r-help/2007-October/142116.html and
https://stat.ethz.ch/pipermail/r-help/2007-October/142124.html]
This is a direct cut and paste from the last url to give you an idea of
Deepayan Sarkar's script

library(lattice)

panel.corval2 <- function(x, y, digits=2, prefix="", cex.cor, ...)
{
    require(grid)
    r <- abs(cor(x, y, use = "complete.obs"))
    txt <- format(c(r, 0.123456789), digits=digits)[1]
    txt <- paste(prefix, txt, sep="")
    if (missing(cex.cor)) cex.cor <- 10 / nchar(txt)
    grid.text(txt, 0.5, 0.5, gp = gpar(cex = cex.cor))
}

splom(iris[1:4], groups = iris$Species, pch = 16,
      lower.panel = function(...) {
          panel.xyplot(...)
          panel.loess(..., col = 1, lwd = 3)
      },
      upper.panel = panel.corval2)


Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of michael
young
Sent: Wednesday, 20 July 2016 03:30
To: r-help at r-project.org
Subject: [R] pairs: adjusting margins and labeling axes

The default shape for this correlation scatterplot is rectangle.  I changed
it to square, but then the x-axis spacing between squares are off.  Is
there an easy way to change x-axis spacing between squares to that of the
y-axis spacing size?

I decided to hide the name values of the diagonal squares.  I want them
along the x and y axis instead, outside of the fixed number scale I have.
I haven't seen any online example of 'pairs' with this and all my searches
have yielded nothing.  Any ideas?  Thanks

par(pty="s")
panel.cor <- function(x, y, digits = 2, prefix="", cex.cor, ...)
{
    usr <- par("usr"); on.exit(par(usr))
    par(usr = c(0, 1, 0, 1),xlog=FALSE,ylog=FALSE)
    # correlation coefficient
    r <- cor(x, y)
    txt <- format(c(r, 0.123456789), digits = digits)[1]
    txt <- paste("r= ", txt, sep = "")
    if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt)
    text(0.5, 0.6, txt, cex=cex.cor * r)

    # p-value calculation
    p <- cor.test(x, y)$p.value
    txt2 <- format(c(p, 0.123456789), digits = digits)[1]
    txt2 <- paste("p= ", txt2, sep = "")
    if(p<0.01) txt2 <- paste("p= ", "<0.01", sep = "")
    text(0.5, 0.4, txt2)
}

pairs(iris, upper.panel = panel.cor,xlim=c(0.1,100000),
ylim=c(0.1,100000),log="xy",text.panel = NULL,pch=".")

	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.



More information about the R-help mailing list