Forum Discussion
Deneb Visual Zooming
- 3 years ago
I have Figured out the solution to this and will paste the code below for anyone who would like to try mimic this.
Essentially, you are able to make a regression graph and make it zoomable but you just have to code within the same Layer ("layer" function). Please take a look below, at the code:{ "data": {"name": "dataset"}, "layer": [ { "mark": { "type": "point", "filled": true }, "encoding": { "x": { "field": "X FIELD", "type": "quantitative", "axis": {"format": "%"} }, "y": { "field": "Y FIELD", "type": "quantitative", "axis": {"format": "%"} }, "color": { "field": "CLIENT COLOUR FIELD - IF THIS IS NOT APPLICABLE TO YOU, PLEASE TAKE IT OUT", "type": "nominal", "legend": null, "scale": { "range": [ "#006D9E", "#A6E2EF" ] } } } }, { "mark": { "type": "line", "color": "black" }, "transform": [ { "regression": "Y FIELD", "on": "X FIELD", "method": "pow" } ], "encoding": { "x": { "field": "X FIELD", "type": "quantitative" }, "y": { "field": "Y FIELD", "type": "quantitative" } } }, { "transform": [ { "regression": "Y FIELD", "on": "X FIELD", "params": true, "method": "pow" } ], "mark": "circle", "encoding": { "x": { "field": "X FIELD", "type": "quantitative" }, "y": { "field": "Y FIELD", "type": "quantitative" } }, "params": [ { "name": "grid", "select": "interval", "bind": "scales" } ] } ] }
Is it possible to show me how to add it to this regression code example at the bottom of this page:
HI , ShivGC
You can try this code if it can help you :
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"url": "data/movies.json"},
"layer": [
{
"mark": {"type": "point", "filled": true},
"encoding": {
"x": {"field": "Rotten Tomatoes Rating", "type": "quantitative"},
"y": {"field": "IMDB Rating", "type": "quantitative"}
},
"selection": {
"selector016": {
"type": "interval",
"bind": "scales",
"encodings": ["x", "y"]
}
}
},
{
"transform": [
{
"regression": "IMDB Rating",
"on": "Rotten Tomatoes Rating",
"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"}}
}
]
}
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
- ShivGC3 years agoHelper I
Hi,
Unfortunately, this is not what I am looking for. I am able to get a typical scatter plot which I am able to zoom in and out of, however, the idea is too add a non-linear regression line to the graph.
This is done on power bi:{ "data": {"name": "dataset"}, "params": [ { "name": "grid", "select": "interval", "bind": "scales" } ], "mark": "circle", "encoding": { "x": { "field": "X Field", "type": "quantitative" }, "y": { "field": "Y Field", "type": "quantitative" } } }
Now, the aim is to add a regression line to it, so that I can zoom into the regression line and see points a little clearer.