[R] pairs: adjusting margins and labeling axes

Greg Snow 538280 at gmail.com
Tue Jul 19 20:16:14 CEST 2016


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



More information about the R-help mailing list