VegaLite Overlay

I have a scatter plot of data in VegaLite. I’d like to overlay a regression line on this plot. Is there a way to do this?

df |> @vlplot(:point, x = :Years, y = :Overall, width = 500, height = 500)

Can I just add the function argument somewhere in here? Thanks.

1 Like

Have a look at
https://www.queryverse.org/VegaLite.jl/stable/examples/examples_advancedcalculations/#Linear-Regression-1

If you want to do it manually or for different kinds of plots, you can use the + syntax like so

using VegaLite
x =  rand(10)
y1 = rand(10)
y2 = rand(10)
p = @vlplot(width = 500, height = 500) + @vlplot(:line, x = x, y = y1) + @vlplot(:point, x = x, y= y2)

Thank you very much! Works perfectly.