Peter Waltman
2005-Jun-06  21:15 UTC
[R] how to generate pairwise plots with data frames - tia
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
Sarah Goslee
2005-Jun-06  21:19 UTC
[R] how to generate pairwise plots with data frames - tia
Peter, Please read the intro to R available on the R web page - you've run into a subsetting problem. The code you specified doesn't select a column from your matrix.> plot(test[1], test[2)Try: plot(test[,1], test[,2]) since test is a two-dimensional construct. Also see ?pairs -- Sarah Goslee http://www.stringpage.com