[R] attribute color to a list

Karim Mezhoud kmezhoud at gmail.com
Fri Aug 28 12:51:28 CEST 2015


Hi,
Thank you for comments.
Yes it is a vector an not a list ;).
I need to round also the input Value (Value <- round(Value, digits=0). If
not Matching is not possible. The vector is a real number and the color.df
are Integer.
Thanks for sapply is better than lapply in my case.
Karim

On Fri, Aug 28, 2015 at 11:35 AM, Jim Lemon <drjimlemon at gmail.com> wrote:

> Hi Karim,
> I'm not sure that this is what is causing the error, but your "list" is
> actually a vector. The following runs, but the function is obviously not
> working:
>
> sapply(list,
>  function(x)
> as.character(attriColorValue(x,list,colors=c("blue","white","red"),feet=1)))
>
> There is probably a better name for your vector than "list".
>
> Jim
>
>
> On Fri, Aug 28, 2015 at 8:16 PM, Karim Mezhoud <kmezhoud at gmail.com> wrote:
>
>> Hi,
>> attriColorValue works with one value. I would like to get the color of a
>> list with lappy but in input I have two variables (the value and the
>> list).
>>
>>
>> attriColorValue <- function(Value, list, colors=c(a,b,c, d,e),feet){
>>
>>      list <- round(list, digits = 0)
>>     Max <- max(list, na.rm=TRUE)
>>     Min <- min(list, na.rm=TRUE)
>>
>>   my.colors <- colorRampPalette(colors)
>>   #generates Max-Min colors from the color ramp
>>   color.df<-data.frame(COLOR_VALUE=seq(Min,Max,feet),
>> color.name=my.colors(length(seq(Min,Max,feet))))
>>
>>   colorRef <- color.df[which(color.df[,1]==Value),2]
>>   return(colorRef)
>> }
>>
>> list <-
>>
>> c(7607.2149,36.0673,26.5613,-21.094,535.1462,8460.8617,3112.3839,1810.5521,-2783.7832,-1283.5496,879.4978,-307.8481,133.6729,51.6518,-212.3436,-118.6624,912.8616,16.7501,465.6139,486.3803,1051.6673,-1529.426,198.9787,-265.013,74.0492,-52.0192,-97.655,-5963.4183,-2118.4033,5701.5644,1987.7252,1638.274,1576.775,1520.7626,1039.4264,905.7974,-966.3739,365.2626,364.8378,258.3969,-323.999,-394.7463)
>>
>> works
>> as.character(attriColorValue(123,list, colors=c("blue","white","red") ,
>> feet=1))
>>
>> not working??
>> lapply(list, function(x) attriColorValue(x,df$exprsMeanDiff ,colors,
>> feet))
>>
>> Thanks
>> Karim
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>>
>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list