Skip to content

Add more docs examples for offset encoding #2604

Open

Description

It would be nice if we could add a page about the new offset encoding that contained common examples. In addition to the offset barplot in the VegaLite docs, I think these examples would be nice:

import altair as alt
from vega_datasets import data

source = data.barley.url

alt.Chart(source).mark_point().encode(
    x='site:O',
    y='yield:Q',
    xOffset='year:N',
    color='year:N',
)

image

alt.Chart(source).mark_point().encode(
    x='site:O',
    y='yield:Q',
    xOffset=alt.XOffset('offset:Q', scale=alt.Scale(domain=(0, 3)))
).transform_calculate(
    offset='random()'
)

image

alt.Chart(source, width=alt.Step(40)).mark_point().encode(
    x='site:O',
    y='yield:Q',
    xOffset=alt.XOffset('offset:Q', scale=alt.Scale(domain=(0, 10))),
    color='year:N'
).transform_calculate(
    offset="datum.year == 1932 ? 5 + random() : 0 + random()"
)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions