Search code examples
rvoronoi

How to change text color in a voronoiTreemap Legend


Here is an example. Text color is black by default.

library(voronoiTreemap)

data(ExampleGDP)
gdp_json <- vt_export_json(vt_input_from_df(ExampleGDP))
vt_d3(gdp_json, legend=TRUE)

Solution

  • WOO HOO! I'm pretty happy with myself on this one. I digress.

    To set the legend text color change this -> '#b21e29' in the following code:

    library(voronoiTreemap)
    library(htmlwidgets)
    library(dplyr)
    
    data(ExampleGDP)
    gdp_json <- vt_export_json(vt_input_from_df(ExampleGDP))
    
    # try number 70032536587832
    (plt = vt_d3(gdp_json, legend=TRUE) %>% 
        onRender("function(el){
                    legends = el.lastChild.lastChild;
                    legends.lastChild.setAttribute('style', 'fill: #b21e29;');
                 }"))
    

    enter image description here