Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faceting with empty panels is broken for time series #471

Open
fabern opened this issue Sep 17, 2023 · 0 comments
Open

Faceting with empty panels is broken for time series #471

fabern opened this issue Sep 17, 2023 · 0 comments

Comments

@fabern
Copy link
Contributor

fabern commented Sep 17, 2023

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:
download
Removing z2 gives wrong x-grid-lines and wrong axis labels (note that y-grid-lines are correct):
download
download

Unliking axes yields different grid-lines and axis labels as expected:
download

Version info

[cbdf2221] AlgebraOfGraphics v0.6.16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant