On 06/10/2011 06:40 AM, Karthik Kota wrote:
Thanks a lot! This is very helpful.

If I have to extend this to one more condition say assign "blue" if both the 
corresponding labels have "_Tongue_dorsum", is there a straight forward function. Doing 
something like below is overriding the colors assigned by the first statement.

col<- ifelse(grepl("_Anterior_nares", xlabels)&  grepl("_Anterior_nares", ylabels), 
"red", "black")
col<- ifelse(grepl("_Tongue_dorsum", xlabels)&  grepl("_Tongue_dorsum", ylabels), "blue", 
"black")

Hi Karthik,
Your problem is that you are assigning all of the values to "col" twice. If you reverse the order of the statements you will get the red/black color set. Try this:

col<-rep("black",dim(cdh1)[1])
col[grepl("_Anterior_nares", xlabels) &
 grepl("_Anterior_nares", ylabels)]<-"red"
col[grepl("_Tongue_dorsum", xlabels) &
 grepl("_Tongue_dorsum", ylabels)]<-"blue"

If your two conditions specify disjunct sets, that is, no case satisfies both conditions, you should have the correct vector of colors.

Jim

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to