knime-mpicbg / knime-scripting

knime-scripting includes scripting extensions for KNIME to integrate R, Matlab, Python and Groovy scripts. These extensions include a collection of nodes to develop and deploy templates in the respective languages.
https://github.com/knime-mpicbg/knime-scripting/wiki
Other
44 stars 25 forks source link

Color model passed to R looses sorting of domain values #99

Closed stoeter closed 6 years ago

stoeter commented 6 years ago

I have used Edit Nominal Domain in KNIME to sort domain values for order of appearance in R-plots. The model port shows exactly what I expect after adding color with the Color Manager (see screen shot). However, the table kIn.color.model has different order and creates a lot of problem in the script in such a way that wrongs color are assigned to the factor/ domain values.

I dont know it this is normal or if this is a bug. I also couldnot find a way yet so solve this on R level. Interestingly, if I use the column name of my sotred domain values (here siRNA) as the name in scale_color_manual, the order of the legend is correct (as in Edit Nominal Domain). However, the colors are not correct.

Martin

capture

CODE: colourCol <- names(kIn.color.model)[1] factorColors <- kIn.color.model[,2] names(factorColors) <- kIn.color.model[,1] p <- p + scale_color_manual(name = colourCol, values = factorColors) p <- p + scale_fill_manual(name = colourCol, values = factorColors)

niederle commented 6 years ago

The 'values' parameter in scale_colour/fill_manual has to be a character vector instead of a factor vector. Otherwise the underlying integer values will be used as color.