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

pos order is inconsistent for different sides #47

Open
willgearty opened this issue Apr 24, 2023 · 1 comment
Open

pos order is inconsistent for different sides #47

willgearty opened this issue Apr 24, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@willgearty
Copy link
Owner

No one has complained about this (yet), but it looks like the behavior of the pos argument is different for whichever side you are specifying.

For example, for the bottom axis, the scales are added from the plot outwards:

ggplot() +
    geom_point(aes(y = runif(1000, 0, 8), x = runif(1000, 0, 100))) +
    scale_x_reverse() +
    coord_geo(
        xlim = c(100, 0), ylim = c(0, 8), pos = as.list(rep("bottom", 3)),
        dat = list("stages", "epochs", "periods"),
        height = list(unit(4, "lines"), unit(4, "lines"), unit(2, "line")),
        rot = list(90, 90, 0), size = list(2.5, 2.5, 5), abbrv = FALSE
    ) +
    theme_classic()

image

But for the top axis, the scales are added from the outside inwards:

ggplot() +
    geom_point(aes(y = runif(1000, 0, 8), x = runif(1000, 0, 100))) +
    scale_x_reverse() +
    coord_geo(
        xlim = c(100, 0), ylim = c(0, 8), pos = as.list(rep("top", 3)),
        dat = list("stages", "epochs", "periods"),
        height = list(unit(4, "lines"), unit(4, "lines"), unit(2, "line")),
        rot = list(90, 90, 0), size = list(2.5, 2.5, 5), abbrv = FALSE
    ) +
    theme_classic()

image

The same is true for left (inside outwards) and right (outside inwards) scales.

@willgearty willgearty added the bug Something isn't working label Apr 24, 2023
@willgearty willgearty self-assigned this Apr 24, 2023
@willgearty
Copy link
Owner Author

willgearty commented Apr 24, 2023

On the one hand, at least their relative positions to one another are the same for top/bottom and for left/right, so maybe this is fine? On the other hand, the behavior of palaeoverse::axis_geo is to always add scales outwards which seems like a good behavior to me.

It shouldn't be too hard to mimic this behavior by just reversing the order of the grobs for the left and top options in this section:

deeptime/R/coord_geo.R

Lines 232 to 264 in 4bf2fdf

if (position == "bottom") {
axis <- CoordTrans$render_axis_h(panel_params, theme)$bottom
gt <- gtable_col("axis",
grobs = c(geo_grobs, list(axis)),
width = one, heights = unit.c(do.call(unit.c, self$height[ind]),
grobHeight(axis))
)
justvp <- viewport(y = 1, just = "top", height = gtable_height(gt))
} else if (position == "top") {
axis <- CoordTrans$render_axis_h(panel_params, theme)$top
gt <- gtable_col("axis",
grobs = c(list(axis), geo_grobs),
width = one, heights = unit.c(grobHeight(axis),
do.call(unit.c, self$height[ind]))
)
justvp <- viewport(y = 0, just = "bottom", height = gtable_height(gt))
} else if (position == "left") {
axis <- CoordTrans$render_axis_v(panel_params, theme)$left
gt <- gtable_row("axis",
grobs = c(list(axis), geo_grobs),
height = one, widths = unit.c(grobWidth(axis),
do.call(unit.c, self$height[ind]))
)
justvp <- viewport(x = 1, just = "right", width = gtable_width(gt))
} else if (position == "right") {
axis <- CoordTrans$render_axis_v(panel_params, theme)$right
gt <- gtable_row("axis",
grobs = c(geo_grobs, list(axis)),
height = one, widths = unit.c(do.call(unit.c, self$height[ind]),
grobWidth(axis))
)
justvp <- viewport(x = 0, just = "left", width = gtable_width(gt))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant