[R] plot(table..) using pairs

Mark Myatt mark at myatt.demon.co.uk
Fri Mar 1 14:18:20 CET 2002


Phil,

Nice to see you here in R-Help ... You write:

>I'm trying to visualise relationships between a number of categorical
>variables with values 0 and 1. 
>
>Plot(table(x,y))
>
> ..works well for one relationship, so I want to use this to examine all
>relationships using pairs function. 
>
>pairs(data_array, upper.panel=panel.tab)
>
>where
>
>panel.tab <- function (x,y)
> {
> plot(tables(x,y))
> }
>
>..produces the error..
>
>Error in pairs.default(a, upper.panel = panel.tab) : 
>        The panel function made a new plot
>
>Can anyone help..?? Many thanks

Use par(new = TRUE) to stop the panel.tab() function making a new plot
from inside the pairs function:

        panel.tab <- function (x,y)
         {
         par(new = TRUE)
         plot(table(x,y))
         }

Have you seen the fourfoldplot() function ... it's for plotting four
fold (i.e. 2-by-2) tables:

        panel.tab <- function (x, y)
         {
         par(new = TRUE)
         fourfoldplot(table(x, y))
         }

Your lower panel looks a bit odd ... you might want to put some text in
there, for example:

  panel.chisq <- function(x, y)
    {
    par(new = TRUE)
    usr <- par("usr")
    on.exit(par(usr))
    par(usr = c(0, 1, 0, 1))
    x2 <- formatC(chisq.test(table(x, y))$p.value,
                  digits = 4, format = "f")
    text(0.5, 0.5, x2, cex = 0.75)
    print(x2)
    }

Display it all with:

  pairs(x, upper.panel = panel.tab, lower.panel = panel.chisq)

I hope that helps,

Mark


--
Mark Myatt
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list