Hi 

I am relatively new to R and am trying to figure out to plot 3d scatter plot using defined colors based on x-axis and y-axis values.  Right now in the code below, I assign colors based on certain values in the names of the x-axis.  Now if I want to extend the condition to assign a color based on the names of both x-axis and y-axis values, what should I be doing? Any help or ideas would be greatly appreciated.

For e.g. in my 3 column matrix below, if I want to assign "red" to all the values whose first column and second column contain "Anterior_nares" and  assign black to any other combination.

Thanks!
Karthik

library(scatterplot3d)

chd1=read.table(file="test.out", header=F, sep="\t")
col=as.vector(chd1[,1])
xlabels=as.vector(chd1[,1])
ylabels=as.vector(chd1[,2])

mycols<-c("red","blue","green","chocolate","orange", "brown")
col[grep("_Stool", xlabels) ]<-mycols[1]
#col[grep("_Stool", xlabels) && grep("_Stool", ylabels) ]<-mycols[1]
col[grep("_Tongue_dorsum", xlabels) ]<-mycols[2]
col[grep("_Posterior_fornix", xlabels) ]<-mycols[3]
col[grep("_Anterior_nares", xlabels) ]<-mycols[4]
col[grep("_Buccal_mucosa", xlabels) ]<-mycols[5]
col[grep("_Supragingival_plaque", xlabels) ]<-mycols[6]


png(file="3dplot_test.png", w=700,h=700)

scatterplot3d(chd1[, 1], chd1[, 2], chd1[, 3], main="test", xlab="sample", ylab="sample", zlab="kmers", color=col,type="p")
dev.off ()


my test.out matrix looks something like this:

A011132_Anterior_nares	A011263_Anterior_nares	50130
A011132_Anterior_nares	A011397_Stool	34748
A011132_Anterior_nares	A012291_Tongue	40859
A011132_Anterior_nares	A012663_Buccal_mucosa	76213
A011132_Anterior_nares	A013155_Anterior_nares	36841
A011132_Anterior_nares	A013269_Anterior_nares	45619
A011132_Anterior_nares	A013637_Anterior_nares	56995
	[[alternative HTML version deleted]]

