0

I am trying to add in a line to represent the mean on a series of charts. I would like a bar chart to be the primary focus with the additional line making it clear which athletes are above/below the mean.

I have tried to add this through layering, but the error message makes it clear that you cannot layer when using alt.repeat.

field_plot = alt.Chart(bauru_stats_field).mark_bar().encode( alt.X(alt.repeat(),type = 'quantitative'), alt.Y('Name', title = 'Player Name', sort = 'x')).repeat(numeric_cols_field, columns = 2) field_plot

enter image description here

joelostblom
  • 43,590
  • 17
  • 150
  • 159

1 Answers1

1

Although you can't layer a repeated chart, you can repeat a layered chart:

import altair as alt
from vega_datasets import data

cars = data.cars.url

chart = alt.Chart(cars).mark_point().encode(
    alt.X(alt.repeat(), type='quantitative'),
    alt.Y('Miles_per_Gallon:Q'),
    color='Origin:N'
)
(chart + chart.mark_square(size=5)).repeat(
    ['Acceleration', 'Horsepower'],
)

enter image description here

joelostblom
  • 43,590
  • 17
  • 150
  • 159