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]]
If you want square plots on a rectangular plotting region, then where do you want the extra space to go? One option would be to add outer margins to use up the extra space. The calculations to figure out exactly how much space to put in the outer margins will probably not be trivial. Another option would be to not use `pairs`, but use the `layout` function directly and loops to do your plots (and use the `respect` argument to `layout`). On Tue, Jul 19, 2016 at 11:29 AM, michael young <nutnutnutterson at gmail.com> wrote:> 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.-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
I want to make this as easy as possible. The extra space could just go around the plot in the margin area. I could then use a cropping tool to paste the plot into Excel or Word. I'm not opposed to using another package, but I'd need some kind of pre-existing code to tinker with. On Tue, Jul 19, 2016 at 11:16 AM, Greg Snow <538280 at gmail.com> wrote:> If you want square plots on a rectangular plotting region, then where > do you want the extra space to go? > > One option would be to add outer margins to use up the extra space. > The calculations to figure out exactly how much space to put in the > outer margins will probably not be trivial. > > Another option would be to not use `pairs`, but use the `layout` > function directly and loops to do your plots (and use the `respect` > argument to `layout`). > > On Tue, Jul 19, 2016 at 11:29 AM, michael young > <nutnutnutterson at gmail.com> wrote: > > 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. > > > > -- > Gregory (Greg) L. Snow Ph.D. > 538280 at gmail.com >[[alternative HTML version deleted]]
Hi Will doing in lattice suite>From https://stat.ethz.ch/pipermail/r-help/2007-October/142116.html andhttps://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.