Cannot add regression line to repeated scatter plots in Altair

Viewed 36

I cannot seem to add a regression line to my repeated scatter plots in Altair as I do not know what to put for x and y in transform_regression('x', 'y').mark_line(). Here's my code, I used cars from vega_datasets.

from vega_datasets import data


source = data.cars()
source 

scatter3 = alt.Chart(source, width=150, height=150).mark_circle().encode(
    alt.X(alt.repeat("row"), type='quantitative'),
    alt.Y(alt.repeat("column"), type='quantitative'),
    alt.Color('Name', legend=None, scale=alt.Scale(scheme='tableau20'))).repeat(
    row=['Miles_per_Gallon', 'Cylinders', 'Displacement', 'Horsepower', 'Weight_in_lbs', 'Acceleration'],
    column=['Miles_per_Gallon', 'Cylinders', 'Displacement', 'Horsepower', 'Weight_in_lbs', 'Acceleration'])
           
scatter3 + scatter3.transform_regression('row', 'column').mark_line()

Can someone help me with the syntax for the last line?

1 Answers
Related