Scatter & Strip Plots

Scatter & Strip Plots

Scatterplot

using VegaLite, VegaDatasets

dataset("cars") |>
@vlplot(:point, x=:Horsepower, y=:Miles_per_Gallon)
050100150200Horsepower01020304050Miles_per_Gallon

Dot Plot

using VegaLite, VegaDatasets

dataset("seattle-weather") |>
@vlplot(:tick, x=:precipitation)
0102030405060precipitation

Strip Plot

using VegaLite, VegaDatasets

dataset("cars") |>
@vlplot(:tick, x=:Horsepower, y="Cylinders:o")
050100150200Horsepower34568Cylinders

Colored Scatterplot

using VegaLite, VegaDatasets

dataset("cars") |>
@vlplot(:point, x=:Horsepower, y=:Miles_per_Gallon, color=:Origin, shape=:Origin)
EuropeJapanUSAOrigin050100150200Horsepower01020304050Miles_per_Gallon

Binned Scatterplot

using VegaLite, VegaDatasets

dataset("movies") |>
@vlplot(
    :circle,
    x={:IMDB_Rating, bin={maxbins=10}},
    y={:Rotten_Tomatoes_Rating, bin={maxbins=10}},
    size="count()"
)
50100150Number of Records12345678910IMDB_Rating (binned)020406080100Rotten_Tomatoes_Rating (binned)

Bubble Plot

using VegaLite, VegaDatasets

dataset("cars") |>
@vlplot(:point, x=:Horsepower, y=:Miles_per_Gallon, size=:Acceleration)
5101520Acceleration050100150200Horsepower01020304050Miles_per_Gallon

Scatterplot with NA Values in Grey

using VegaLite, VegaDatasets

dataset("movies") |>
@vlplot(
    :point,
    x=:IMDB_Rating,
    y=:Rotten_Tomatoes_Rating,
    color={
        condition={
            test="datum.IMDB_Rating === null || datum.Rotten_Tomatoes_Rating === null",
            value="#aaa"
        }
    },
    config={invalidValues=nothing}
)
0246810IMDB_Rating020406080100Rotten_Tomatoes_Rating

Scatterplot with Filled Circles

using VegaLite, VegaDatasets

dataset("cars") |>
@vlplot(:circle, x=:Horsepower, y=:Miles_per_Gallon)
050100150200Horsepower01020304050Miles_per_Gallon

Bubble Plot (Gapminder)

using VegaLite, VegaDatasets

dataset("gapminder-health-income") |>
@vlplot(
    :circle,
    width=500,height=300,
    selection={
        view={typ=:interval, bind=:scales}
    },
    y={:health, scale={zero=false}},
    x={:income, scale={typ=:log}},
    size=:population,
    color={value="#000"}
)
200,000,000400,000,000600,000,000800,000,0001,000,000,0001,200,000,000population1002001,0002,00010,00020,000100,000200,0001,000,000income455055606570758085health

Bubble Plot (Natural Disasters)

using VegaLite, VegaDatasets

dataset("disasters") |>
@vlplot(
    width=600,height=400,
    transform=[
        {filter="datum.Entity !== 'All natural disasters'"}
    ],
    mark={
        :circle,
        opacity=0.8,
        stroke=:black,
        strokeWidth=1
    },
    enc={
        x={"Year:o", axis={labelAngle=0}},
        y={:Entity, axis={title=""}},
        size={
            :Deaths,
            legend={title="Annual Global Deaths"},
            scale={range=[0,5000]}
        },
        color={:Entity, legend=nothing}
    }
)
1,000,0002,000,0003,000,000Annual Global Deaths190019011902190319051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017YearDroughtEarthquakeEpidemicExtreme temperatureExtreme weatherFloodLandslideMass movement (dry)Volcanic activityWildfire

Scatter Plot with Text Marks

using VegaLite, VegaDatasets

dataset("cars") |>
@vlplot(
    :text,
    transform=[
        {
            calculate="datum.Origin[0]",
            as="OriginInitial"
        }
    ],
    x=:Horsepower,
    y=:Miles_per_Gallon,
    color=:Origin,
    text="OriginInitial:n"
)
UUUUUUUUUUUUUUJUUUJEEEEEUUUUUJUJUUUUUUUUUUUUUUUUUEEEJJEUJUEUUUUUUUUUUUJUUUUEEEEUJJUJUUUUUUUUUUUUUUUUUEUUUUUJUJJUUEUUEEEEUEJUUUUJUJUUUUUUUUUEEEJJUEEJJEUUUUUUUUUUUUUUUJUUUJEJUEUEEEEJEEUUEUUUUUUUUUUEJUUUUEJJUEUEJEUUUUJUEUJUUUUUUUUUUUUEUJUUUJEJEJEUJJJUUUUUUUUUUUUUUUUUUJJUJUUJEEEEEJUUUUUUUUUUUUUEJUUEUEUUUJEUUUUEJUJUUUUEJJJJJUJEEEEJJEJJEJUUUUUJUJJJJJUUUEJJJJEEJJUUUUUUUUUUUEJJUUJJJJJJUUUUJUUUEUUUEuropeJapanUSAOrigin050100150200Horsepower01020304050Miles_per_Gallon