This is a little complicated in Polychart currently, although we are trying to create a more R friendly solution. But for now, here is the way to set custom scales in Polychart
p2$guides(color = list(scale = "#! function(value){
color_mapping = {one: '#ff2385', two: '#229922'}
return color_mapping[value];
} !#"))
The idea is to set a scale for the color aesthetic. But instead of using a color palette, you specify a function, which returns a color based on the mapping. You need to wrap the function between #!
and !#
so that rCharts treats it as a JS literal, and does not stringify it when converting to JSON.
If you are unsure how to specify color_mapping
in JSON, you can use the function toJSON
to convert your R object. Only caveat is avoid using double quotes inside the function, as they tend to get escaped and as a result cause errors.
Hope this was useful.