user20901436
user20901436

Reputation:

Regression Line not showing on Vega Lite

I am trying to add a Regression transformation to a scatterplot however i cannot get the Line to appear on the visualisation.

"layer":[{
"mark": {
"type":"circle",
"color":"rgb(0,47,167)",
"size":60},


"encoding": {
 "x": {
  "field": "supply", 
  "type": "quantitative",
  "title":null
  },

"y": {
  "field": "price", 
  "type": "quantitative",
  "title":null
  }}},

{
  "mark": {"type": "line", "color": "firebrick"},
  "transform": [
    {"regression": "price", "on": "supply"}
  ],
  "encoding": {
    "x": {"field": "supply", "type": "quantitative"},
    "y": {"field": "price", "type": "quantitative"}
  }
},
{
  "transform": [
    {
      "regression": "price",
      "on": "supply",
      "params": true
    },
    {"calculate": "'R²: '+format(datum.rSquared, '.2f')", "as": "R2"}
  ],
  "mark": {
    "type": "text",
    "color": "firebrick",
    "x": "width",
    "align": "right",
    "y": -5
  },
  "encoding": {"text": {"type": "nominal", "field": "R2"}}
}
]

[Link to json]https://github.com/GeorgeRobbin/GeorgeRobbin.github.io/blob/main/CHART6_Regression.json

Upvotes: 0

Views: 74

Answers (1)

davidebacci
davidebacci

Reputation: 30174

The line is there but it is very tiny.

enter image description here

Upvotes: 0

Related Questions