You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

echarts4r中geom_abline()的等效实现:绘制(0,0)至(1,1)基准线

解决方案:添加(0,0)至(1,1)的基准线

要添加从(0,0)到(1,1)的基准线,需要调整e_mark_line的参数,明确指定起点和终点的坐标,而不是只设置xAxis = 0。

修改后的完整代码如下:

compare() %>% 
  tibble::rownames_to_column("Brand") %>% 
  e_charts(Benchmark) %>% 
  e_scatter(Actual, symbol_size = 10, bind = Name) %>% 
  e_labels(formatter = htmlwidgets::JS("function(params) {
    return(params.name)
  }")) %>% 
  # 定义基准线的起点和终点坐标
  e_mark_line(
    data = list(
      list(xAxis = 0, yAxis = 0),
      list(xAxis = 1, yAxis = 1)
    ),
    # 可选:设置基准线样式,比如虚线
    lineStyle = list(type = "dashed")
  ) %>% 
  e_tooltip()

关键说明:

  • e_mark_line的data参数需要传入包含两个点的列表,分别对应(0,0)和(1,1),通过xAxis和yAxis指定每个点在对应轴上的数值。
  • 可以通过lineStyle参数自定义基准线的样式,比如设置虚线、颜色等,提升可视化效果。

内容的提问来源于stack exchange,提问作者fantom

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 13:54:57