Table-based Plots

Table Heatmap

using VegaLite, VegaDatasets

dataset("cars") |>
@vlplot(:rect, y=:Origin, x="Cylinders:o", color="mean(Horsepower)")
76158Mean of Horsepower34568CylindersEuropeJapanUSAOrigin

Annual Weather Heatmap

using VegaLite, VegaDatasets

dataset("seattle-temps") |>
@vlplot(
    title="2010 Daily Max Temperature (F) in Seattle, WA",
    :rect,
    x={
        "date:o",
        timeUnit=:date,
        title="Day",
        axis={labelAngle=0,format="%e"}
    },
    y={
        "date:o",
        timeUnit=:month,
        title="Month"
    },
    color={
        "temp:q",
        aggregate="max",
        legend={title=nothing}
    },
    config={
        view={
            strokeWidth=0,
            step=13
        },
        axis={
            domain=false
        }
    }
)
42762010 Daily Max Temperature (F) in Seattle, WA12345678910111213141516171819202122232425262728293031DayJanFebMarAprMayJunJulAugSepOctNovDecMonth

2D Histogram Heatmap

using VegaLite, VegaDatasets

dataset("movies") |>
@vlplot(
    :rect,
    width=300, height=200,
    x={:IMDB_Rating, bin={maxbins=60}},
    y={:Rotten_Tomatoes_Rating, bin={maxbins=40}},
    color="count()",
    config={
        view={
            stroke="transparent"
        }
    }
)
5101520Count of Records1.21.41.61.82.02.22.42.62.83.03.23.43.63.84.04.24.44.64.85.05.25.45.65.86.06.26.46.66.87.07.27.47.67.88.08.28.48.68.89.09.2IMDB_Rating (binned)05101520253035404550556065707580859095100Rotten_Tomatoes_Rating (binned)

Table Bubble Plot (Github Punch Card)

using VegaLite, VegaDatasets

dataset("github") |>
@vlplot(
    :circle,
    y="day(time):o",
    x="hours(time):o",
    size="sum(count)"
)
00:0001:0002:0003:0004:0005:0006:0007:0008:0009:0010:0011:0012:0013:0014:0015:0016:0017:0018:0019:0020:0021:0022:0023:00time (hours)SunMonTueWedThuFriSattime (day)1020304050Sum of count

Layering text over heatmap

using VegaLite, VegaDatasets

cars = dataset("cars")

@vlplot(
    data=cars,
    y="Origin:o",
    x="Cylinders:o",
    config={
        scale={bandPaddingInner=0, bandPaddingOuter=0},
        text={baseline=:middle}
    }
) +
@vlplot(:rect, color="count()") +
@vlplot(
    :text,
    text="count()",
    color={
        condition={
            test="datum['count_*'] > 100",
            value=:black
        },
        value=:white
    }
)
1086669747246433108Count of Records34568CylindersEuropeJapanUSAOrigin

Lasagna Plot (Dense Time-Series Heatmap)

using VegaLite, VegaDatasets

dataset("stocks") |>
@vlplot(
    width=300,
    height=100,
    transform=[{filter="datum.symbol!=='GOOG'"}],
    mark=:rect,
    x={
        "date:o",
        timeUnit=:yearmonthdate,
        title="Time",
        axis={
            format="%Y",
            labelAngle=0,
            labelOverlap=false,
            labelColor={
                condition={
                    test={
                        field="value",
                        timeUnit=:monthdate,
                        equal={month=1,date=1}
                    },
                    value="black"
                },
                value=nothing
            },
            tickColor={
                condition={
                    test={
                        field="value",
                        timeUnit=:monthdate,
                        equal={month=1,date=1}
                    },
                    value="black"
                },
                value=nothing
            }
        }
    },
    y={
        "symbol:n",
        title=nothing
    },
    color={
        "price:q",
        aggregate="sum",
        title="Price"
    }
)
6223Price200020002000200020002000200020002000200020002000200120012001200120012001200120012001200120012001200220022002200220022002200220022002200220022002200320032003200320032003200320032003200320032003200420042004200420042004200420042004200420042004200520052005200520052005200520052005200520052005200620062006200620062006200620062006200620062006200720072007200720072007200720072007200720072007200820082008200820082008200820082008200820082008200920092009200920092009200920092009200920092009201020102010TimeAAPLAMZNIBMMSFT

Mosaic Chart with Labels

using VegaLite, VegaDatasets

dataset("cars") |>
@vlplot(
    resolve={scale={x="shared"}},
    config={
        view={stroke=""},
        concat={spacing=10},
        axis={
            domain=false,
            ticks=false,
            labels=false,
            grid=false
        }
    },
    transform=[
        {
            aggregate=[{op="count",as="count_*"}],
            groupby=["Origin","Cylinders"]
        },
        {
            stack="count_*",
            groupby=[],
            as=["stack_count_Origin1","stack_count_Origin2"],
            offset="normalize",
            sort=[{field="Origin",order="ascending"}]
        },
        {
            window=[
                {op="min",field="stack_count_Origin1",as="x"},
                {op="max",field="stack_count_Origin2",as="x2"},
                {op="dense_rank",as="rank_Cylinders"},
                {op="distinct",field="Cylinders",as="distinct_Cylinders"}
            ],
            groupby=["Origin"],
            frame=[nothing,nothing],
            sort=[{field="Cylinders",order="ascending"}]
        },
        {
            window=[
                {op="dense_rank",as="rank_Origin"}
            ],
            frame=[nothing,nothing],
            sort=[{field="Origin",order="ascending"}]
        },
        {
            stack="count_*",
            groupby=["Origin"],
            as=["y","y2"],
            offset="normalize",
            sort=[{field="Cylinders",order="ascending"}]
        },
        {calculate="datum.y + (datum.rank_Cylinders - 1) * datum.distinct_Cylinders * 0.01 / 3",as="ny"},
        {calculate="datum.y2 + (datum.rank_Cylinders - 1) * datum.distinct_Cylinders * 0.01 / 3",as="ny2"},
        {calculate="datum.x + (datum.rank_Origin - 1) * 0.01",as="nx"},
        {calculate="datum.x2 + (datum.rank_Origin - 1) * 0.01",as="nx2"},
        {calculate="(datum.nx+datum.nx2)/2",as="xc"},
        {calculate="(datum.ny+datum.ny2)/2",as="yc"},
        {calculate="'Origin: '+datum.Origin+', '+'Cylinders: '+datum.Cylinders",as="tt"}, #How to add a line break?
    ]
) +
[
    @vlplot(
        mark={
            :text,
            baseline="middle",
            align="center"
        },
        x={
            "xc:q",
            aggregate="min",
            title="Origin",
            axis={orient=:top}
        },
        color={
            "Origin:n",
            legend=nothing
        },
        text="Origin:n"
    );
    (
        @vlplot() +
        @vlplot(
            :rect,
            x={"nx:q",axis=nothing},
            x2=:nx2,
            y={"ny:q",axis=nothing},
            y2=:ny2,
            color={"Origin:n",legend=nothing},
            opacity={field="Cylinders",type="quantitative",legend=nothing},
            #tooltip=[{field="Origin",type="nominal"},{field="Cylinders",type="quantitative"}]  #array not supported
            tooltip={"tt:n"} #see calculate above
        ) +
        @vlplot(
            mark={:text,baseline="middle"},
            x={"xc:q",axis=nothing},
            y={"yc:q",axis={title="Cylinders"}},
            text="Cylinders:n"
        )
    )
]
OriginUSAEuropeJapan844643665

Wind Vector Map

using VegaLite, VegaDatasets

dataset("windvectors") |>
@vlplot(
    mark={:point, shape=:wedge},
    x={"longitude:o", axis=nothing},
    y={"latitude:o", axis=nothing},
    color={"dir:q", scale={domain=[0,360], scheme=:rainbow},legend=nothing},
    angle={"dir:q", scale={domain=[0,360], range=[180, 540]}},
    size="speed:q",
    config={view={step=10, fill=:black}}
)
24681012speed