0

Hello and thanks for reading me. Im trying to create a plot with conditional colors and I want to have the same colors for the scatter serie, but im just getting the custom color for the first serie. How I can apply the custom color for both series?

The code is the following:

library(echarts4r)
library(dplyr)

tibble(
  year = as.character(sample(1950:2020, 100, replace = T)),
  y = rnorm(100, 10, 3)
) |> 
  head(10) |> 
  mutate(
    color = if_else(y > 9, "red", "green")
  ) |> 
  e_charts(year) |> 
  e_bar(y ) |> 
  e_scatter(y) |> 
  e_add_nested("itemStyle", color) 

Thanks for the help

  • it seems that the e_add_nested() funtion only affects the first series. I tried e_data() as a way to add the second series, but no luck. Interesting problem – rdatasculptor Nov 12 '22 at 12:39

1 Answers1

1

Instead of itemStyle you can use the e_visual_map as following :

tibble(
  year = as.character(sample(1950:2020, 100, replace = T)),
  y = rnorm(100, 10, 3)
) |> 
head(10) |> 
mutate(
  color = if_else(y > 9, "red", "green")
) |> 
e_charts(year) |> 
e_bar(y) |> 
e_scatter(y) |>
e_visual_map(
  type = "piecewise",
  pieces = list(
    list(
     gt = 9,
     color = "red"
    ),
    list (
     lte = 9,
     color = "green"
  )
 )
)
Thor6
  • 781
  • 6
  • 9