Faceting (Trellis Plot / Small Multiples)

Faceting (Trellis Plot / Small Multiples)

Trellis Bar Chart

using VegaLite, VegaDatasets

dataset("population") |>
@vlplot(
    :bar,
    transform=[
        {filter="datum.year==2000"},
        {calculate="datum.sex==2 ? 'Female' : 'Male'",as=:gender}
    ],
    row="gender:n",
    y={"sum(people)", axis={title="population"}},
    x={"age:o", scale={rangeStep=17}},
    color={"gender:n", scale={range=["#EA98D2", "#659CCA"]}}
)
genderFemale02,000,0004,000,0006,000,0008,000,00010,000,00012,000,000populationMale02,000,0004,000,0006,000,0008,000,00010,000,00012,000,000population051015202530354045505560657075808590ageFemaleMalegender

Trellis Stacked Bar Chart

using VegaLite, VegaDatasets

dataset("barley") |>
@vlplot(:bar, column="year:o", x="sum(yield)", y=:variety, color=:site)
yearGlabronManchuriaNo. 457No. 462No. 475PeatlandSvansotaTrebiVelvetWisconsin No. 38variety19311932050100150200250Sum of yield050100150200250Sum of yieldCrookstonDuluthGrand RapidsMorrisUniversity FarmWasecasite

Trellis Scatter Plot

using VegaLite, VegaDatasets

dataset("movies") |>
@vlplot(:point, column="MPAA_Rating:o", x=:Worldwide_Gross, y=:US_DVD_Sales)
MPAA_Rating0100,000,000200,000,000300,000,000400,000,000US_DVD_SalesnullGNot RatedPGPG-13R0500,000,0001,000,000,0001,500,000,0002,000,000,0002,500,000,000Worldwide_Gross0500,000,0001,000,000,0001,500,000,0002,000,000,0002,500,000,000Worldwide_Gross0500,000,0001,000,000,0001,500,000,0002,000,000,0002,500,000,000Worldwide_Gross0500,000,0001,000,000,0001,500,000,0002,000,000,0002,500,000,000Worldwide_Gross0500,000,0001,000,000,0001,500,000,0002,000,000,0002,500,000,000Worldwide_Gross0500,000,0001,000,000,0001,500,000,0002,000,000,0002,500,000,000Worldwide_Gross

Trellis Histograms

using VegaLite, VegaDatasets

dataset("cars") |>
@vlplot(
    :bar,
    x={
        :Horsepower,
        bin={maxbins=15}
    },
    y="count()",
    row=:Origin
)
OriginEurope020406080Number of RecordsJapan020406080Number of RecordsUSA020406080Number of Records4080120160200240Horsepower (binned)

Trellis Scatter Plot showing Anscombe's Quartet

using VegaLite, VegaDatasets

dataset("anscombe") |>
@vlplot(
    :circle,
    column=:Series,
    x={:X, scale={zero=false}},
    y={:Y, scale={zero=false}},
    opacity={value=1}
)
Series4681012YIIIIIIIV5101520X5101520X5101520X5101520X

Becker's Barley Trellis Plot

using VegaLite, VegaDatasets

dataset("barley") |>
@vlplot(
    :point,
    row="site:o",
    x={"median(yield)", scale={zero=false}},
    y={
        "variety:o",
        sort={
            "yield",
            op=:median,
            order=:descending
        },
        scale={rangeStep=12}},
    color=:year
)
siteCrookstonTrebiWisconsin No. 38No. 457GlabronPeatlandVelvetNo. 475ManchuriaNo. 462SvansotavarietyDuluthTrebiWisconsin No. 38No. 457GlabronPeatlandVelvetNo. 475ManchuriaNo. 462SvansotavarietyGrand RapidsTrebiWisconsin No. 38No. 457GlabronPeatlandVelvetNo. 475ManchuriaNo. 462SvansotavarietyMorrisTrebiWisconsin No. 38No. 457GlabronPeatlandVelvetNo. 475ManchuriaNo. 462SvansotavarietyUniversity FarmTrebiWisconsin No. 38No. 457GlabronPeatlandVelvetNo. 475ManchuriaNo. 462SvansotavarietyWasecaTrebiWisconsin No. 38No. 457GlabronPeatlandVelvetNo. 475ManchuriaNo. 462Svansotavariety10203040506070Median of yield1,931.01,931.21,931.41,931.61,931.81,932.0year

Trellis Area

using VegaLite, VegaDatasets

dataset("stocks") |>
@vlplot(
    :area,
    width=300,height=40,
    transform=[{filter="datum.symbol !== 'GOOG'"}],
    x={
        "date:t",
        axis={format="%Y",title="Time",grid=false}
    },
    y={
        :price,
        axis={title="Price",grid=false}
    },
    color={
        :symbol,
        legend=nothing
    },
    row={
        :symbol,
        header={title="Symbol"}
    }
)
SymbolAAPL0200PriceAMZN0200PriceIBM0200PriceMSFT0200Price20002001200220032004200520062007200820092010Time