Skip to content

scatterplot3d - help assign colors based on multiple conditions

6 messages · Karthik Kota, Uwe Ligges, Jim Lemon

#
On 09.06.2011 16:51, Karthik Kota wrote:
Both question and answer are not really scatterplot3d related: You 
probably want

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

Best,
Uwe Ligges
#
On 09.06.2011 22:40, Karthik Kota wrote:
In that case go for it with your original way by, e.g., replacing

col[grepl("_Anterior_nares", xlabels) &  grepl("_Anterior_nares", 
ylabels)] <- mycols[4]

Uwe
#
On 06/10/2011 06:40 AM, Karthik Kota wrote:
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
#
Thanks! That did the trick.
On Jun 10, 2011, at 3:16 AM, Jim Lemon wrote: