[R] Plot overview xy plots from data frame?

Jim Lemon jim at bitwrit.com.au
Thu Oct 15 09:59:11 CEST 2009


On 10/15/2009 07:40 AM, Joel Fürstenberg-Hägg wrote:
> Hi,
>
> I've got a data frame (556 rows and 36 columns) from which I need to create several xy plots and print to pdf, in order to detect outliers and trends in the data. 16 of the columns contains numerical values, and I would like to create graphs for all combinations. It can be done manually, but creating 256 plots by hand takes time... I guess I have to iterate through the data frame, but I'm not used to do that with R. Below I've written my thoughts, trying to combine my knowledge in Java and R, just to give you the idea:
>
> pdf("FieldTrial0809Overview.pdf")
>
> int colWidth = fieldTrial[0].length;
>
>
> for(i=0, i<colWidth, i++)
> {
>      for(j=0, j<colWidth, j++)
>      {
>          String colI=get.fieldTrial$i;
>          String colJ=get.fieldTrial$j;
>
>          plot(fieldTrial$i~fieldTrial$j, main=colI + " vs " + colJ, xlab=colI, ylab=colJ)
>      }
> }
>
> dev.off()
>
> Anyone who know how to solve this?
> Do I have to copy the 16 numerical columns to a new dataset, because they are not grouped and there are 20 additional non-numerical columns in the data frame.
> By the way, can the iterations be made using R, or do you have to combine with for instance Perl?
>
>    
Hi Joel,
If by "all combinations" you mean all pairwise combinations, then if 
your numeric columns are numbers 5 to 20, you could do this:

allpairs<-combn(5:20,2)
for(i in 1:dim(allpairs)[2]) {
  pdf(
   paste("FieldTrial0809Overview",
   allpairs[1,i],allpairs[2,i],sep="_"))
  plot(fieldTrial[,allpairs[1,i]],fieldTrial[,allpairs[2,i]],...)
  dev.off()
}

Jim




More information about the R-help mailing list