<jupyter_start><jupyter_text>Compound Charts**Learning Objective:** Be able to create compound chart with layers, horizontal and vertical concatenation, and repeating.These examples are taken from the Altair documentation:https://altair-viz.github.io/user_guide/compound_charts.html<jupyter_code>import altair as alt
alt.data_transformers.enable('json')
from vega_datasets import data<jupyter_output><empty_output><jupyter_text>Layered charts Layered charts enable you to overlay multiple charts on a single facet or subchart.<jupyter_code>from altair.expr import datum

from vega_datasets import data
stocks = data.stocks.url

base = alt.Chart(stocks).encode(
    x='date:T',
    y='price:Q',
    color='symbol:N'
).transform_filter(
    datum.symbol == 'GOOG'
)

base.mark_line() + base.mark_point()
alt.layer(
  base.mark_line(),
  base.mark_point(),
  base.mark_rule()
).interactive()<jupyter_output><empty_output><jupyter_text>Horizontal concatenation Horizontal concatenation enables you to place two charts side-by-side, without a group-by relationship between the charts.<jupyter_code>iris = data.iris.url

chart1 = alt.Chart(iris).mark_point().encode(
    x='petalLength:Q',
    y='petalWidth:Q',
    color='species:N'
).properties(
    height=300,
    width=300
)

chart2 = alt.Chart(iris).mark_bar().encode(
    x='count()',
    y=alt.Y('petalWidth:Q', bin=alt.Bin(maxbins=30)),
    color='species:N'
).properties(
    height=300,
    width=100
)

chart1 | chart2
alt.hconcat(chart1, chart2)<jupyter_output><empty_output><jupyter_text>Vertical concatenation Vertical concatenation enables you to place two chart above/below each other, without a group-by relationship between the charts.<jupyter_code>sp500 = data.sp500.url

brush = alt.selection(type='interval', encodings=['x'])

upper = alt.Chart(sp500).mark_area().encode(
    x=alt.X('date:T', scale={'domain': brush.ref()}),
    y='price:Q'
).properties(
    width=600,
    height=200
)

lower = upper.properties(
    selection=brush,
    height=60
)

alt.vconcat(upper, lower)<jupyter_output><empty_output><jupyter_text>Repeated charts Repeated charts enable you to create a particular type of horizontal or vertical stacking, where the charts vary only in one or more encodings.<jupyter_code>iris = data.iris.url

base = alt.Chart().mark_point().encode(
    color='species:N'
).properties(
    width=200,
    height=200
).interactive()

chart = alt.vconcat(data=iris)
for y_encoding in ['petalLength:Q', 'petalWidth:Q']:
    row = alt.hconcat()
    for x_encoding in ['sepalLength:Q', 'sepalWidth:Q']:
        row |= base.encode(x=x_encoding, y=y_encoding)
    chart &= row
chart
import altair as alt
from vega_datasets import data
iris = data.iris.url

alt.Chart(iris).mark_point().encode(
    alt.X(alt.repeat("column"), type='quantitative'),
    alt.Y(alt.repeat("row"), type='quantitative'),
    color='species:N'
).properties(
    width=200,
    height=200
).repeat(
    row=['petalLength', 'petalWidth'],
    column=['sepalLength', 'sepalWidth']
).interactive()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1350293542074364, 'fraction_numerical': 0.01598173515981735, 'mean_word_length': 5.2719836400818, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '456530', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1036, 'n_words': 226, 'path': 'Content/Visualize/06-CompoundCharts.ipynb', 'repo_name': 'calpolydatascience/ds4e', 'size': '3066'}