Skip to content

Collect axes: tick mis-alignment #436

Open

Description

@mayer79

Fantastic package.

Currently, I am evaluating the options to collect axis_titles, axes, and guides.

I am hitting the issue that axes with identical labels but different tick positions are collected:

library(ggplot2)
library(patchwork)

x <- data.frame(
  x = c(-0.1, 1, 2, 1, 2, 3, 4, 1), 
  z = c(-0, 1, 2, 1, 2, 3, 4.1, 1), 
  y = 1:8
)

p1 <- ggplot(x, aes(x, y)) +
  geom_point()

p2 <- ggplot(x, aes(z, y)) +
  geom_point()

wrap_plots(list(p1, p2), axes = "collect", axis_titles = "collect", ncol = 1)

Image

My workaround is to call get_guide_data(), check if all columns correspond across plots and set axes correctly.

get_guide_data(p1, aesthetic = "x")
#                    x .value .label y
# 1 0.06762749      0      0 0
# 2 0.28935698      1      1 0
# 3 0.51108647      2      2 0
# 4 0.73281596      3      3 0
# 5 0.95454545      4      4 0

get_guide_data(p2, aesthetic = "x")
#                  x .value .label y
# 1 0.04545455      0      0 0
# 2 0.26718404      1      1 0
# 3 0.48891353      2      2 0
# 4 0.71064302      3      3 0
# 5 0.93237251      4      4 0

# Also useful
ggplot2::get_labs(p1)

Is this behaviour as intended?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions