[R] pairs: adjusting margins and labeling axes

William Michels wjm1 at caa.columbia.edu
Thu Jul 21 01:57:42 CEST 2016


Hi Michael, is this the direction you'd like to go (simplified)?

?pairs
pairs(iris, log="xy", asp=1, gap=0.1)

--Bill.


On Tue, Jul 19, 2016 at 2:37 PM, Michael Young <aimfrendio at gmail.com> wrote:

> 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]]
>
> ______________________________________________
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list