'Cannot add regression line to repeated scatter plots in Altair
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?
Solution 1:[1]
Ah, I see what you want to do. Unfortunately this is not possible yet in VegaLite, which is what Altair is built upon. You can follow the progress in the following two issues:
One way to get around this is to use faceting as shown in the answer here Quick way to visualise multiple columns in Altair with regression lines
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | joelostblom |
