Search code examples
rechartsecharts4r

How to add different color for your liquid using e_liquid() in R


I'm trying to create a liquifill chart using e_liquid() from echarts4R library.

So this is a code from https://echarts4r.john-coene.com/articles/chart_types.html#liquifill:

liquid <- data.frame(val = c(0.2, 0.5, 0.4))

liquid |> 
  e_charts() |> 
  e_liquid(val) |> 
  e_theme( name = "dark")

I want to change the color , there's a color argument in e_liquid() but it can only take column names.

Thanks for the help.


Solution

  • As you have already mentioned, you need to pass the wave colors in your data frame. Otherwise, you can pass additional settings to the ellipsis (...) of the e_liquid function. The background can be set using the e_color function:

    liquid <- data.frame(val = c(0.7, 0.5, 0.4), colors = c("blue", "green", "red"))
    
    library(echarts4r)
    
    liquid |> 
      e_charts() |> 
      e_liquid(val, color = colors, 
               backgroundStyle = list(borderColor = "yellow", 
                                      color = "orange",
                                      borderWidth = 20),
               label = list(fontSize = 100,
                            color = "purple")) |> 
      e_color(background = c("grey"))
    

    The documentation provides this link for echarts. From this example, it should be clearer to you how to set other options.

    The above code produces this horrendously colored graphic (but hopefully it is clear what color settings alter which features of the graphic):

    enter image description here