0

In the following reproducible example I would like to map the year value to a continuous color scale (with all the points with a manually selected and fixed size). The points are not of the expected color...

library(echarts4r)

d <- data.frame(
    x = rnorm(30), 
    y = rnorm(30), 
    year = rep(2000:2014, 2)
)

d |> 
    e_chart(x) |> 
    e_scatter(y, symbol_size = 10, bind = year, legend = FALSE) |> 
    e_visual_map(year, color = c("#8DD3C7", "#FFFFB3", "#BEBADA", "#FB8072")) |> 
    e_tooltip()
Gilles San Martin
  • 4,224
  • 1
  • 18
  • 31

1 Answers1

1

Looks like a bug: the year column is not in the series object of the echart object. Here is a way to include it and the code to produce the plot:

library(echarts4r)

d <- data.frame(
  x = rnorm(30), 
  y = rnorm(30), 
  year = rep(2000:2014, 2)
)

dd <- lapply(purrr::transpose(d), function(row) list(value = unname(unlist(row))))

ECHART <- d |> 
  e_charts(x) |> 
  e_scatter(y, symbol_size = 10, legend = FALSE) |> 
  e_visual_map(year, dimension = 2, inRange = list(color = c("#8DD3C7", "#FFFFB3", "#BEBADA", "#FB8072"))) |> 
  e_tooltip()

ECHART$x$opts$series[[1]]$data <- dd
ECHART
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
  • Thank you ! Not certain if this is a bug or a "feature". I see that there is already a bug reprot on github : https://github.com/JohnCoene/echarts4r/issues/492 Perfect ! – Gilles San Martin Dec 01 '22 at 03:06