R lattice - trying to change labels colors with y.scale.components customisation -


i try customise lattice parallel plot, changing y axis label colors, depending on character of these same lables. created customised y.scale.components function, described in many books/forums. however, after assigning vector of new colors ans$left$labels$col parameter, default color (black) used plot.

here's code:

test2 <- read.table(textconnection("           species  evalue l1 l2  l3    daphnia.pulex  1.0e-6 17 41  35    daphnia.pulex 1.0e-10 11 30  25    daphnia.pulex 1.0e-20  4 14  17    daphnia.pulex 1.0e-35  4  8  15    daphnia.pulex 1.0e-50  1  4   8    daphnia.pulex 1.0e-75  0  2   6 ixodes.scapularis  1.0e-6  7 20 118 ixodes.scapularis 1.0e-10  6 17 107 ixodes.scapularis 1.0e-20  4  6  46 ixodes.scapularis 1.0e-35  2  3  14 ixodes.scapularis 1.0e-50  0  0   5 ixodes.scapularis 1.0e-75  0  0   2 ")->con,header=t);close(con)  #data.frame assign color data, depending on species names on y axis orga<-c("daphnia.pulex","ixodes.scapularis") color<-c("cornsilk2","darkolivegreen1" ); phylum<-c("arthropoda","arthropoda" ); colorchooser<-data.frame(orga,color,phylum)  #fonction custom rendering of left y axis labels  yscale.components.custom<-function(...) {   ans<-yscale.components.default(...)   #vector new label colors, grey60 default   new_colors<-c()   new_colors<-rep("grey60",length(ans$left$labels$labels))   # for() check labels character , assign corresponding color colorchooser data.frame   n<-1   (i in ans$left$labels$labels) {       new_colors[n]<-as.character(colorchooser$color[colorchooser$orga==i])       #got color corresponding label, colorchooser dataframe   n<-n+1   }   print(length(new_colors))   cat(new_colors,sep="\n")  #print content of generated color vector   ans$left$labels$col<-new_colors  #assign vector col parameter   ans }  #plot bwplot(   reorder(species,l1,median)~l1,       data=test2,       panel = function(..., box.ratio) {             panel.grid(h=length(colnames(cdata[,annot.arthro]))-1,v=0,col.line="grey80")             panel.violin(..., col = "white",varwidth = false, box.ratio = box.ratio )             panel.bwplot(..., fill = null, box.ratio = .07)       },       yscale.components=yscale.components.custom ) 

here's output of cat() command, included in yscale.components.custom function. can see, outputs 2 times color labels, vector assigned ans$left$labels$col of length 2. there second call setup y axis labels colors ? come ?

[1] 2 darkolivegreen1 cornsilk2 [1] 2 darkolivegreen1 cornsilk2 

any welcome, don't undestand why colors assigned ans$left$labels$col drawn in black. change violin border colors, using same colorchooser data.frame, that's story...

after asking deepayan sarkar, ans$left$labels$col value apparently ignored during lattice execution.

i used different solution "scales" argument. unfortunately, cannot anymore rely on lattice reorder function reorder data series median.

for code mentionned above, order them manually, create vector of color corresponding order. cannot rely on lattice reordering anymore (the "reorder" in lattice formula). then, setup axix labels colors

scales=list(col=c(color1,color2,...)) 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -