[R] how to generate pairwise plots with data frames - tia

Peter Waltman pwaltman at cs.tufts.edu
Mon Jun 6 23:15:36 CEST 2005


hi -

sorry for a newbie question, but I've tried to go through the 
documentation and couldn't find anything that would address my specific 
need.

in a nutshell, I have a txt file containing a data matrix with 10 
columns of data.  I would like to generate pairwise plots of the data, 
i.e. 1 column against the other 9.  Since this will produce 50 plots, 
I'd like to do it using a loop.  However, I can't figure out how to do 
it as it seems like I have to specify the column name within the plot 
function.

for example, if I have:

    test <- read.delim("matrix.txt")

and then try to generate a plot of the first 2 columns via:

    plot(test[1], test[2)

I get an error message:

    Error in pmatch(x, table, duplicates.ok) :
            argument is not of mode character

but if I specify these columns by their column headers, i.e.:

    attach(test)
    plot(Control_200, Control_201)

it works just fine.  However, with 10 columns, this will produce ~ 50 
pairwise plots, so I'd really like to figure out how to automate this.  
I've tried getting the names of the data frame and using those, i.e.:

    myNames<-names(test)
    plot(test$myNames[1], test$myNames[2])

but that doesn't work either as the myNames members are strings, not the 
variables themselves (I believe).

is it possible to get a listing of the variables themselve, not the 
names and work off of those?

thanks to anyone who can help shed some light on this,

Peter Waltman




More information about the R-help mailing list