# Vegalite.jl Linear Fitting & Question of Controlling Interface

**URL:** https://discourse.julialang.org/t/vegalite-jl-linear-fitting-question-of-controlling-interface/34681
**Category:** Visualization
**Created:** [February 15, 2020, 3:46pm UTC](https://discourse.julialang.org/t/vegalite-jl-linear-fitting-question-of-controlling-interface/34681 "2020-02-15T15:46:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Usor](https://avatars.discourse-cdn.com/v4/letter/u/8dc957/32.png) [@Usor](https://discourse.julialang.org/u/Usor)
#### Post date: [February 15, 2020, 3:46pm UTC](https://discourse.julialang.org/t/vegalite-jl-linear-fitting-question-of-controlling-interface/34681/1 "2020-02-15T15:46:20Z")

</div>

What is the easiest most basic example of quickly fitting to a simple scatterplot using Vegalite.jl? (Say, with two columns of some numbers.)

My other question is whether there are any plans to again have that higher general interface (I believe its name is Plots) to steer Vegalite.jl like it steers other vis. packages.

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [February 15, 2020, 4:22pm UTC](https://discourse.julialang.org/t/vegalite-jl-linear-fitting-question-of-controlling-interface/34681/2 "2020-02-15T16:22:38Z")

</div>

If you can use VegaLite#master this is an example which is probably not the simplest one but you may adapt it to your needs:

```julia
using VegaLite, VegaDatasets

dataset("movies") |>
@vlplot(
layer=[{
    mark={:point,filled=true},
    x="Rotten_Tomatoes_Rating:q",
    y="IMDB_Rating:q"
},
{
    transform=[
        {
            regression="IMDB_Rating",
            on="Rotten_Tomatoes_Rating"
        }
    ],
    mark={:line,color="firebrick"},
    x="Rotten_Tomatoes_Rating:q",
    y="IMDB_Rating:q"
},
{
    transform=[
        {
            regression="IMDB_Rating",
            on="Rotten_Tomatoes_Rating",
            params=true
        },
        {
            calculate="'R²: '+format(datum.rSquared, '.2f')",
            as="R2"
        }
    ],
    mark={:text,color="firebrick",x="width",align="right",y=-5},
    text={"R2:n"}
}]
)

```

It is an adaption of

> **[Linear Regression](https://vega.github.io/vega-lite/examples/layer_point_line_regression.html)**
>
> Vega-Lite - a high-level grammar for statistical graphics. Vega-Lite provides a higher-level grammar for visual analysis, comparable to ggplot or Tableau, that generates complete Vega specifications. Vega-Lite specifications consist of simple...

Using the Julia way of layers with `) + @vlplot(` doesnt work and I didn’t found out why yet.

---

<div class="post-metadata">

### Author: ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)
#### Post date: [February 15, 2020, 7:52pm UTC](https://discourse.julialang.org/t/vegalite-jl-linear-fitting-question-of-controlling-interface/34681/3 "2020-02-15T19:52:28Z")

</div>

There is also hope that at some point we will get an even easier syntax for this scenario, see [this issue](https://github.com/vega/vega-lite/issues/3988) on the original vega-lite repo.

---

<div class="post-metadata">

### Author: ![Usor](https://avatars.discourse-cdn.com/v4/letter/u/8dc957/32.png) [@Usor](https://discourse.julialang.org/u/Usor)
#### Post date: [February 16, 2020, 2:55pm UTC](https://discourse.julialang.org/t/vegalite-jl-linear-fitting-question-of-controlling-interface/34681/4 "2020-02-16T14:55:14Z")

</div>

Thanks for your responses.

Your opening of that issue, David, seems indeed in order. A concise simple way would be indeed preferrable.

(And I suppose for the moment that that concise general and overarching Plots support for Vegalite.jl will not exist. I recall an answer where it was said that Vegalite.jl is for manual and specific control anyway. But certainly there is good value in that overarching support.)
