AlgebraOfGraphics.jl
AlgebraOfGraphics.jl copied to clipboard
Faceting with empty panels is broken for time series
Bug description
Similar to issue #50: when faceting and a panel is empty it leads to wrong grid lines and axis labels. While this works for a numeric x-axis, it does not when using DateTime
as x-axis.
Steps to reproduce
using AlgebraOfGraphics, CairoMakie
using DataFrames, DataFramesMeta
using Dates
x = today() - Year(2) : Day(1) : today()
x = DateTime.(x)
y1 = cumsum(randn(length(x)))
y2 = cumsum(randn(length(x)))
z1 = cumsum(randn(length(x))) * 10
z2 = cumsum(randn(length(x))) * 10
dat = DataFrame(
dates = repeat(x,4),
variable = repeat(["y","z"], inner=length(x)*2, outer = 1),
series = repeat(["1","2"], inner=length(x), outer = 2),
value = [y1; y2; z1; z2])
# With all facets filled, labels and gridlines appear correct.
draw(data(dat) *
mapping(
:dates, :value,
color = :series,
col = :series, row = :variable),
axis = (width = 400, height = 225))
# With missing facets, gridlines (and labels) are wrong:
draw(data(@rsubset(dat, !(:variable == "y" && :series == "2"))) *
mapping(
:dates, :value,
color = :series,
col = :series, row = :variable),
axis = (width = 400, height = 225))
draw(data(@rsubset(dat, !(:variable == "z" && :series == "2"))) *
mapping(
:dates, :value,
color = :series,
col = :series, row = :variable),
axis = (width = 400, height = 225))
draw(data(@rsubset(dat, !(:variable == "z" && :series == "2"))) *
mapping(
:dates, :value,
color = :series,
col = :series, row = :variable),
axis = (width = 400, height = 225),
facet=(; linkxaxes=:minimal, linkyaxes=:minimal))
draw(data(@rsubset(dat, !(:variable == "z" && :series == "2"))) *
mapping(
:dates, :value,
color = :series,
col = :series, row = :variable),
axis = (width = 400, height = 225),
facet=(; linkxaxes=:none, linkyaxes=:none))
Images
This works:
Removing z2 gives wrong x-grid-lines and wrong axis labels (note that y-grid-lines are correct):
Unliking axes yields different grid-lines and axis labels as expected:
Version info
[cbdf2221] AlgebraOfGraphics v0.6.16