I ran into a problem with "subset" while working at home that I am not sure is a bug or not.  I defined a custom function to take a data frame of tree positions, sizes, and types (containing the columns TRT, COMP, PLOT, X, Y, DBH and CON) and wanted to make a stem map of the plot using different symbols and colors to represent the different types of tree stems.  I copied a bit of the code below, the part that gave me troubles:

if(dim(subset(mat,CON==1 & DBH>11.43))[1]>0) symbols(mat[mat$CON==1 &     mat$DBH>11.43,]$X,mat[mat$CON==1 & mat$DBH>11.43,]$Y,circles=log(mat[mat$CON==1 & mat$DBH>11.43,]$DBH)*tuner,inches=FALSE,add=TRUE,fg="gray",lwd=2)

if(dim(subset(mat,CON==0 & DBH>11.43))[1]>0) symbols(mat[mat$CON==0 & mat$DBH>11.43,]$X,mat[mat$CON==0 & mat$DBH>11.43,]$Y,squares=log(mat[mat$CON==0 & mat$DBH>11.43,]$DBH)*sqrt(pi)*tuner,inches=FALSE,add=TRUE,fg="gray",lwd=2)

if(dim(subset(mat,CON==1 & DBH<=11.43))[1]>0) symbols(mat[mat$CON==1 & mat$DBH<=11.43,]$X,mat[mat$CON==1 & mat$DBH<=11.43,]$Y,circles=log(mat[mat$CON==1 & mat$DBH<=11.43,]$DBH)*tuner,inches=FALSE,add=TRUE,fg="black",lwd=2)

if(dim(subset(mat,CON==0 & DBH<=11.43))[1]>0) symbols(mat[mat$CON==0 & mat$DBH<=11.43,]$X,mat[mat$CON==0 & mat$DBH<=11.43,]$Y,squares=log(mat[mat$CON==0 & mat$DBH<=11.43,]$DBH)*sqrt(pi)*tuner,inches=FALSE,add=TRUE,fg="black",lwd=2)

 The item "tuner" just scales the symbol size.  As you can see, I was using two columns to define the type of symbol (CON: square vs. circle) and color (DBH: gray vs. black).  I had to use the "if" statements because some of the plots did not contain all combinations of tree types.  This worked fine in giving me my plots.

Okay, the question I had was why I couldn't use the "subset" function within the "symbols" command.  I was going to use:

subset(mat,CON==0 & DBH<=11.43,select=c(X,Y))

as the first entry into the symbols command, but it kept giving me errors saying "xy.coords" could not convert it.  However, if I used the "plot" function with "subset" trimming the data frame externally, it worked fine to plot the point positions.  However, the help for "plot" and "plot.default" says "xy.coords" is used within that function.  What am I missing here?

Mike Saunders
Research Assistant
University of Maine
 
	[[alternative HTML version deleted]]


