The Chart Missing From ALL Spreadsheet Software

This example is inspired in the video (https://www.youtube.com/watch?v=5zBg9pH_6bE) by the Minute Physics channel. The idea is to used floating stacked bars to represent data such as temperature ranges. Check the video for a discussion on this specific visualization.

using Vizagrams
using DataFrames
using CSV
path = joinpath(pkgdir(Vizagrams), "docs", "src", "assets", "weather.csv")
df = DataFrame(CSV.File(path))
5×4 DataFrame
RowColumn1OntarioEnglandKentucky
String31Int64Int64Int64
1winter mean low-93-3
2annual mean low388
3annual mean81214
4annual mean high131620
5summer mean high272430

Once we import the data, we must transform the dataframe such that each row contains a pair of temperature values for a given range.

df = stack(df, [:Ontario, :England, :Kentucky], variable_name=:location, value_name=:value)

coalg_pairwise(lst) = [(lst[i],lst[i+1]) for i in 1:length(lst)-1]
df = combine(groupby(df,:location)) do gdf
    hcat(
        DataFrame(coalg_pairwise(gdf[!,:Column1]),[:label_low,:label_high]),
        DataFrame(coalg_pairwise(gdf[!,:value]),[:low_temp,:high_temp])
    )
end
df[!,:label_temp] = df[!,:label_low] .* " | " .* df[!,:label_high]
df
12×6 DataFrame
Rowlocationlabel_lowlabel_highlow_temphigh_templabel_temp
StringString31String31Int64Int64String
1Ontariowinter mean lowannual mean low-93winter mean low | annual mean low
2Ontarioannual mean lowannual mean38annual mean low | annual mean
3Ontarioannual meanannual mean high813annual mean | annual mean high
4Ontarioannual mean highsummer mean high1327annual mean high | summer mean high
5Englandwinter mean lowannual mean low38winter mean low | annual mean low
6Englandannual mean lowannual mean812annual mean low | annual mean
7Englandannual meanannual mean high1216annual mean | annual mean high
8Englandannual mean highsummer mean high1624annual mean high | summer mean high
9Kentuckywinter mean lowannual mean low-38winter mean low | annual mean low
10Kentuckyannual mean lowannual mean814annual mean low | annual mean
11Kentuckyannual meanannual mean high1420annual mean | annual mean high
12Kentuckyannual mean highsummer mean high2030annual mean high | summer mean high

We can now use Vizagrams to express the graphic.

plt = Plot(
    config = (;yaxis=(;title="Temperature (°C)")),
    data=df,
    x = :location,
    y = (field=:high_temp,scale_domain=(-10,40), scale_range=(0,200)),
    low_y = (field=:low_temp,scale_domain=(-10,40), scale_range=(0,200)),
    color = (field=:label_temp,scale_range=["#F28E2B","#4E79A7","#FFBE7D","#A0CBE8"]),
    graphic =
        ∑() do row
            S(:fill=>row.color,:stroke=>:white)*
            Trail([[row.x,row.low_y],[row.x,row.y]],20)
        end
)

draw(plt, height=400)
EnglandKentuckyOntariolocation-10010203040Temperature (°C)EnglandKentuckyOntariolocation-10010203040Temperature (°C)label_tempannual mean high | summer mean highannual mean low | annual meanannual mean | annual mean highwinter mean low | annual mean low