R: Creates a paneled plot like pairs for two different datasets.

pairwiseplot {compositions} | R Documentation

## Creates a paneled plot like pairs for two different datasets.

### Description

Creates a plot for each element of two lists or each column of each dataset against each of the second.

### Usage

    pairwisePlot(X,Y,...)
    ## Default S3 method:
    pairwisePlot(X,Y=X,...,
                    xlab=deparse(substitute(X)),ylab=deparse(substitute(Y)),
                    nm=c(length(Y),length(X)),panel=plot,
                    add.line=FALSE, line.col=2,add.robust=FALSE,rob.col=4)

### Arguments

`X` | a list, a data.frame, or a matrix representing the first set of things to be displayed.
`Y` | a list, a data.frame, or a matrix representing the second set of things to be displayed.
`...` | furter parameters to the panel function
`xlab` | The sequence of labels for the elements of X. Alternatively the labels can be given as colnames or names of X. This option takes precedence if specified.
`ylab` | The sequence of labels for the elements of Y. Alternatively the labels can be given as colnames or names of Y. This option takes precedence if specified.
`nm` | the parameter to be used in the call `par(mfrow=nm)`. If NULL no parameter is setted and a sequence of plots can be generated.
`panel` | The panel function to plot the individual panels. If the panel function admits a formula interface, it is called as `panel(y~x, xlab=xlab,ylab=ylab,...)`, otherwise as `panel(x, y,xlab=xlab,ylab=ylab,...)`. Thus the panel function must be capable of taking these arguments. It must also set up its own plot. There is no negotiation on coordinate system.
`add.line` | logical, to control the addition of a regression line in each panel
`line.col` | in case the regression line is added, which color should be used? defaults to red.
`add.robust` | logical, to control the addition of a robust regression line in each panel. Ignored if covariable is a factor. This is nowadays based on `lmrob`, but this can change in the future.
`rob.col` | in case the robust regression line is added, which color should be used? Defaults to blue.

### Details

This is a light-weight convenience function to plot several aspects of one dataset against several aspects of another dataset. It is far more straight-forward than e.g. the `pairs` function and does not do any internal computation rather than organizing the names. Of course, the rows of the two data sets must be the same.

The current implementation may display a warning about the function `panel` dispatching methods for generic `plot`. It can be ignored without harm.

Optionally, classical and/or robust regression lines can be drawn, though only for non-factor covariables.

It may be convenient to use `par` capabilities to fit the device characteristics to the plot, in particular arguments `mar` and `oma`.

### Author(s)

K.Gerald v.d. Boogaart http://www.stat.boogaart.de, Raimon Tolosana-Delgado

### References

Boogaart, K.G. v.d. , R. Tolosana (2008) Mixing Compositions and Other scales, Proceedings of CodaWork 08.

http://ima.udg.es/Activitats/CoDaWork03

http://ima.udg.es/Activitats/CoDaWork05

http://ima.udg.es/Activitats/CoDaWork08

### See Also

`plot.aplus`, `balance`, `pwlrPlot`

### Examples

    X <- rnorm(100)
    Y <- rnorm.acomp(100,acomp(c(A=1,B=1,C=1)),0.1*diag(3))+acomp(t(outer(c(0.2,0.3,0.4),X,"^")))

    pairs(cbind(ilr(Y),X),panel=function(x,y,...) {points(x,y,...);abline(lm(y~x))})
    pairs(cbind(balance(Y,~A/B/C),X),
             panel=function(x,y,...) {points(x,y,...);abline(lm(y~x))})
    pairwisePlot(balance(Y,~A/B/C),X)
    pairwisePlot(X,balance(Y,~A/B/C),
             panel=function(x,y,...) {plot(x,y,...);abline(lm(y~x))})
    pairwisePlot(X,balance01(Y,~A/B/C))

    # A function to extract a portion representation of subcompsitions
    # with two elements:
    subComps <- function(X,...,all=list(...)) {
      X <- oneOrDataset(X)
      nams <- sapply(all,function(x) paste(x[[2]],x[[3]],sep=","))
      val  <- sapply(all,function(x){
                 a = X[,match(as.character(x[[2]]),colnames(X)) ]
                 b = X[,match(as.character(x[[2]]),colnames(X)) ]
                 c = X[,match(as.character(x[[3]]),colnames(X)) ]
                 return(a/(b+c))
               })
      colnames(val)<-nams
      val
    }

    pairwisePlot(X,subComps(Y,A~B,A~C,B~C))

    ## using Hydrochemical data set as illustration of mixed possibilities
    data(Hydrochem)
    xc = acomp(Hydrochem[,c("Ca","Mg","Na","K")])
    fk = Hydrochem$River
    pH = -log10(Hydrochem$H)
    covars = data.frame(pH, River=fk)
    pairwisePlot(clr(xc), pH)
    pairwisePlot(clr(xc), pH, col=fk)
    pairwisePlot(pH, ilr(xc), add.line=TRUE)
    pairwisePlot(covars, ilr(xc), add.line=TRUE, line.col="magenta")
    pairwisePlot(clr(xc), covars, add.robust=TRUE)

[Package compositions version 1.40-3 Index]