Skip to content
Back to formatted view

Raw Message

Message-ID: <4DF1D2CD.4090906@bitwrit.com.au>
Date: 2011-06-10T08:16:13Z
From: Jim Lemon
Subject: scatterplot3d - help assign colors based on multiple	conditions
In-Reply-To: <76D1DF14-97C6-4F14-86FA-8B001894F262@genome.wustl.edu>

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