piRSquared
piRSquared

Reputation: 294218

Name or title facets

I am using the cars data set. I used a trick to wrap facets. In other words, instead of creating a multifaceted plot with 12 rows or 12 columns (one for each Year in the data set) I used div and mod to create 2 rows of 6 columns.

import pandas as pd
import altair as alt
from vega_datasets import data

cars = pd.read_json(data.cars.url)
cars['year_row'], cars['year_col'] = \
    pd.to_datetime(cars_.Year).dt.year.factorize()[0].__divmod__(6)

alt.Chart(cars).mark_bar().encode(
    alt.X('Cylinders:O'),
    alt.Y('mean(Acceleration):Q'),
    alt.Color('Origin:N'),
    alt.Column('year_col', title=None),
    alt.Row('year_row', title=None),
)

enter image description here

The question is: Can I place a title for each facet so that I know what year it is? And if so, how?

Upvotes: 1

Views: 730

Answers (1)

jakevdp
jakevdp

Reputation: 86310

No, there is no way to add titles to individual subplots when you construct a chart in this way.

Note that while vega-lite does not currently support what you are trying to do (i.e. wrapped facets) there is work underway to support it natively, so that this sort of plot will be much easier to create in the future. See https://github.com/vega/vega-lite/issues/393

Upvotes: 1

Related Questions