[R] conditional coloring of image labels

Jake Michaelson jjmichael at cc.usu.edu
Fri Nov 11 20:36:44 CET 2005


On Friday 11 November 2005 10:37 am, Jake Michaelson wrote:

I'll clarify a little and hopefully this will make more sense (thanks for the 
friendly encouragement):

Let's say I have 6 samples and am looking at 3 genes, with intensities in a 
matrix as follows:

> genes=cbind(ABC1=c(3,4,4,5,6,3), ABC2=c(4,3,4,7,7,8), ABC3=c(8,7,8,6,3,2))
> genes
     ABC1 ABC2 ABC3
[1,]    3    4    8
[2,]    4    3    7
[3,]    4    4    8
[4,]    5    7    6
[5,]    6    7    3
[6,]    3    8    2

###plot the image
>image(1:nrow(genes), 1:ncol(genes), genes, axes = FALSE, xlab = "", ylab = 
"", col=cm.colors(256))
 
###label the axes
>axis(1, 1:nrow(genes), labels = rownames(genes), las = 2, line = -0.5, tick = 
0)

>axis(2, 1:ncol(genes), labels = colnames(genes), las = 2, line = -0.5, tick = 
0)

Now let's say (I'm just making these numbers and the scenario up here -- for 
simplicity's sake) that I had run a statistical analysis previously and 
wanted to label the genes that showed a significance of p< 0.05.  Let's say 
that ABC1 and ABC3 had p<0.05 (assume that these values would be in a 
two-column matrix with the gene name and its p-value). 

> sig=cbind(name=c("ABC1", "ABC2", "ABC3"), pvalue=c(0.005, 0.1, 0.001))
> sig
     name   pvalue 
[1,] "ABC1" "0.005"
[2,] "ABC2" "0.1"  
[3,] "ABC3" "0.001"

 I now want these (the names of the significant genes) to be labeled in red 
rather than black on the plot.  I would eventually write a script that would 
generate a large number of these images, each with a different set of genes. 
I would like to insert some sort of conditional formatting so that if that 
gene meets the significance threshold, the name is automatically plotted in 
red on the plot.

I hope this is more clear and effective in explaining what I'm looking for.


Thanks,

--Jake




> Hi all,
>
> I am interested in plotting a heatmap of a set of genes.  I would like the
> text labels of these genes to be colored red rather than black if they meet
> certain statistical criteria (using an if statement).  I'm not sure how to
> change individual color labels without changing them all.  Can anyone
> provide some insight on how to do this?
>
> Thanks in advance,
>
> Jake
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list