Coming from Python I tried to reproduce this Seaborn heatmap using Gadfly. The (only) issue I have is that the first and last columns appear smaller than the other columns. As a result the annotations are not fully readable. Is there an option to set all cells to “equal squares” or an other solution?
using DataFrames
using CSV
using Gadfly
using Compose
using ColorSchemes
# download dataset
download("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/flights.csv", "flights.csv");
flights = DataFrame(CSV.File("flights.csv"))
# prepare annotation
flights_unstacked = unstack(flights, :month, :year, :passengers)
x = [x for x in 1949:1960 for y in 1:12]
y = repeat(collect(1:12), outer=12)
txt = string.(Array(flights_unstacked[:, 2:end]))
# plot heatmap
set_default_plot_size(16cm, 12cm)
plot(
flights,
x=:year,
y=:month,
color=:passengers,
Geom.rectbin,
Scale.ContinuousColorScale(palette -> get(ColorSchemes.magma, palette)),
Coord.cartesian(xmin=minimum(flights.year), xmax=maximum(flights.year)),
Guide.xticks(ticks=[minimum(flights.year):maximum(flights.year);]),
Theme(background_color = "white"),
Guide.annotation(
compose(
context(),
text(x, y, txt, [hcenter], [vcenter]),
fontsize(7pt),
stroke("white")
)
),
)