echarts4r icon indicating copy to clipboard operation
echarts4r copied to clipboard

Scatter plot with colorbar using e_visual_map: the third dimension is not retained in the series

Open stla opened this issue 1 year ago • 0 comments

Hello,

Maybe I don't use the appropriate code; the following code does not produce the expected result:

library(echarts4r)

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

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()

I also tried to add bind = year, same result.

I inspected the echarts4r object and it turns out that the year column (corresponding to dimension = 2) is not present in the series[[1]]$data object, that's why that doesn't work. So I manually modified this object as follows, and this works:

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

stla avatar Nov 30 '22 13:11 stla