
:orphan:
:html_theme.sidebar_secondary.remove:

.. This document is auto-generated by the altair-gallery extension. Do not modify directly.

.. _gallery_beckers_barley_facet:


Becker's Barley Faceted Plot
----------------------------
The example demonstrates the faceted charts created by Richard Becker,
William Cleveland and others in the 1990s. Using the visualization technique
where each row is a different site (i.e. the chart is faceted by site),
they identified an anomaly in a widely used agriculatural dataset,
where the "Morris" site accidentally had the years 1931 and 1932 swapped.
They named this
`"The Morris Mistake." <http://ml.stat.purdue.edu/stat695t/writings/Trellis.User.pdf>`_.


.. altair-plot::
    :remove-code:
    


    import altair as alt
    from altair.datasets import data

    source = data.barley()

    alt.Chart(source, title="The Morris Mistake").mark_point().encode(
        alt.X(
            'yield:Q',
            title="Barley Yield (bushels/acre)",
            scale=alt.Scale(zero=False),
            axis=alt.Axis(grid=False)
        ),
        alt.Y(
            'variety:N',
            title="",
            sort='-x',
            axis=alt.Axis(grid=True)
        ),
        color=alt.Color('year:N', legend=alt.Legend(title="Year")),
        row=alt.Row(
            'site:N',
            title="",
            sort=alt.EncodingSortField(field='yield', op='sum', order='descending'),
        )
    ).properties(
        height=alt.Step(20)
    ).configure_view(stroke="transparent")


.. tab-set::

    .. tab-item:: Method syntax
        :sync: method

        .. code:: python


            import altair as alt
            from altair.datasets import data

            source = data.barley()

            alt.Chart(source, title="The Morris Mistake").mark_point().encode(
                alt.X('yield:Q')
                    .title("Barley Yield (bushels/acre)")
                    .scale(zero=False)
                    .axis(grid=False),
                alt.Y('variety:N')
                    .title("")
                    .sort('-x')
                    .axis(grid=True),
                alt.Color('year:N')
                    .title("Year"),
                alt.Row('site:N')
                    .title("")
                    .sort(field='yield', op='sum', order='descending')
            ).properties(
                height=alt.Step(20)
            ).configure_view(stroke="transparent")


    .. tab-item:: Attribute syntax
        :sync: attribute

        .. code:: python


            import altair as alt
            from altair.datasets import data

            source = data.barley()

            alt.Chart(source, title="The Morris Mistake").mark_point().encode(
                alt.X(
                    'yield:Q',
                    title="Barley Yield (bushels/acre)",
                    scale=alt.Scale(zero=False),
                    axis=alt.Axis(grid=False)
                ),
                alt.Y(
                    'variety:N',
                    title="",
                    sort='-x',
                    axis=alt.Axis(grid=True)
                ),
                color=alt.Color('year:N', legend=alt.Legend(title="Year")),
                row=alt.Row(
                    'site:N',
                    title="",
                    sort=alt.EncodingSortField(field='yield', op='sum', order='descending'),
                )
            ).properties(
                height=alt.Step(20)
            ).configure_view(stroke="transparent")
