简体   繁体   English

echarts4r:如何将第三个连续变量 map 转换为自定义色标(不改变点大小)

[英]echarts4r : how to map a third continuous variable to a custom color scale (without changing the points size)

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).在下面的可重现示例中,我想将年份值 map 转换为连续色标(所有点都具有手动选择和固定大小)。 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()

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:看起来像一个错误: year列不在echart object 的系列 object 中。这是一种包含它的方法以及生成 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM