首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >向vega-lite散点图添加回归线

向vega-lite散点图添加回归线
EN

Stack Overflow用户
提问于 2019-07-22 22:21:17
回答 1查看 277关注 0票数 2

我试图在我的vega-lite图中添加一条简单的回归线,但我不确定where to integrate this code有什么想法?

代码语言:javascript
复制
let spec = {
      "data": { "values": iris },
      "mark": "point",
      "encoding": {
        "x": {"field": "Sepal_Length","type": "quantitative"},
        "y": {"field": "Sepal_Width","type": "quantitative"}
      }
    }

vegaEmbed("#vis", spec, {})

我已经把所有的代码都包含在这个小提琴里了:https://jsfiddle.net/MayaGans/qdj20Lws/如果有任何帮助,我将非常感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-22 23:57:07

Vega-Lite没有任何内置的计算回归线的能力。但是,如果您预先计算了回归线,则可以使用分层图表将它们放在同一轴上。例如:

代码语言:javascript
复制
{
  "layer": [
    {
      "data": {"url": "data/iris.json"},
      "mark": "point",
      "transform": [
        {"filter": "datum.species == 'setosa'"}
      ],
      "encoding": {
        "x": {"type": "quantitative", "field": "sepalWidth"},
        "y": {"type": "quantitative", "field": "sepalLength"}
      }
    },
    {
      "data": {
        "values": [
          {"x": 0, "y": 2},
          {"x": 5, "y": 6.5}
        ]
      },
      "mark": "line",
      "encoding": {
        "x": {"type": "quantitative", "field": "x"},
        "y": {"type": "quantitative", "field": "y"}
      }
    }
  ]
}

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57148066

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档