Skip to content

How can I facet on multiple variables? #3601

Answered by joelostblom
rongcuid asked this question in Q&A
Discussion options

You must be logged in to vote

There is currently no support for that in Vega-Lite so it is not available in Altair. Instead, you can create the new combined column with the dataframe library you're using, or directly in altair using transform_calculate:

import pandas as pd


mpg = pd.read_csv('https://raw.githubusercontent.com/has2k1/plotnine/4159f9548fa5f95c02366efc324e88f9ba79af09/plotnine/data/mpg.csv')

alt.Chart(mpg, width=100, height=100).mark_point().transform_calculate(
    man_model_drv=alt.expr.slice([alt.datum.manufacturer, alt.datum.model, alt.datum.drv])
    # Equivalent JS string expression
    # man_model_drv='[datum.manufacturer, datum.model, datum.drv]'
).encode(
    x='cty',
    y='hwy',
).facet(
    '…

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@rongcuid
Comment options

@joelostblom
Comment options

Answer selected by rongcuid
@dangotbanned
Comment options

@joelostblom
Comment options

@rongcuid
Comment options

@joelostblom
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants