I am using this example https://altair-viz.github.io/user_guide/transform/regression.html for plotting a regression trendline in altair.
import altair as alt
import pandas as pd
import numpy as np
np.random.seed(42)
x = np.linspace(0, 10)
y = x - 5 + np.random.randn(len(x))
df = pd.DataFrame({'x': x, 'y': y})
chart = alt.Chart(df).mark_point().encode(
x='x',
y='y'
)
chart + chart.transform_regression('x', 'y').mark_line()
Additionally, I want to add the rSquared-value as text to the chart. How can I access the value? According to the documentation, it should be something like:
chart + chart.transform_regression('x', 'y', params=True).mark_text()