我试图在我的vega-lite图中添加一条简单的回归线,但我不确定where to integrate this code有什么想法?
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/如果有任何帮助,我将非常感谢!
发布于 2019-07-22 23:57:07
Vega-Lite没有任何内置的计算回归线的能力。但是,如果您预先计算了回归线,则可以使用分层图表将它们放在同一轴上。例如:
{
"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"}
}
}
]
}

https://stackoverflow.com/questions/57148066
复制相似问题