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

[BUG] geom_swim_label() Introduces Scale Imbalance #49

Open
4 of 5 tasks
rsh52 opened this issue Jun 24, 2024 · 0 comments
Open
4 of 5 tasks

[BUG] geom_swim_label() Introduces Scale Imbalance #49

rsh52 opened this issue Jun 24, 2024 · 0 comments
Labels
backlog Backlog items for the future or that may not be worked on bug Something isn't working

Comments

@rsh52
Copy link
Contributor

rsh52 commented Jun 24, 2024

Expected Behavior

In a perfect world, the order of geom_swim_label() / geom_swim_point() wouldn't matter and the legend would render either way they are called.

Current Behavior

Due to geom_swim_label()s use of guides() to force emojis where glyphs typically reside, ordering does matter. For the time being, this is low priority and may not be addressed with the current setup of ggplot and ggnewscale.

Here is an example of two working ggswim setups:

# swim point call before label call
patient_data |>
  ggplot() +
  geom_swim_point(data = infusion_events,
                  mapping = aes(x = time_from_initial_infusion, y = pt_id, colour = infusion_type)) +
  geom_swim_label(data = end_study_events,
                  mapping = aes(x = time_from_initial_infusion, y = pt_id,
                                label_vals = end_study_label, label_names = end_study_name))

# swim label before point with new_scale_color()
patient_data |>
  ggplot() +
  geom_swim_label(data = end_study_events,
                  mapping = aes(x = time_from_initial_infusion, y = pt_id,
                                label_vals = end_study_label, label_names = end_study_name),
                  label.size = NA, fill = NA, size = 5) +
  new_scale_color() +
  geom_swim_point(data = infusion_events,
                  mapping = aes(x = time_from_initial_infusion, y = pt_id, colour = infusion_type))

How to Reproduce the Bug:

And here is one that fails, where geom_swim_label() is called before geom_swim_point() and without new_scale_color():

patient_data |>
  ggplot() +
  geom_swim_label(data = end_study_events,
                  mapping = aes(x = time_from_initial_infusion, y = pt_id,
                                label_vals = end_study_label, label_names = end_study_name),
                  label.size = NA, fill = NA, size = 5) +
  geom_swim_point(data = infusion_events,
                  mapping = aes(x = time_from_initial_infusion, y = pt_id, colour = infusion_type))

Current Solution

In commit ec13553 we reintroduced try_ggswim() which will detect this type of error and return it with slightly more context and suggestion of how to fix it.

Failure Logs

The typical error without try_ggswim():

Error:
✖ `[[<-.data.frame`(`*tmp*`, i, value = list(end_study_label = c("✅", "❌", "⚠️"))) replacement has 3 rows, data has 5

And the updated error with try_ggswim():

Error:
✖ `[[<-.data.frame`(`*tmp*`, i, value = list(end_study_label = c("", "", "⚠️"))) replacement has 3 rows, data has 5
! Scale misalignment detected when rendering ggswim.This can often be resolved by calling `new_scale_color()` or reordering point and label geoms.

Update 2024-09-03: This only seems to work for certain cases. It does not always capture or trigger try_ggswim(). Fixed in recent commit.

Checklist

Before submitting this issue, please check and verify below that the submission meets the below criteria:

  • The issue is atomic
  • The issue description is documented
  • The issue title describes the problem succinctly
  • Developers are assigned to the issue
  • Labels are assigned to the issue
@rsh52 rsh52 added bug Something isn't working backlog Backlog items for the future or that may not be worked on labels Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Backlog items for the future or that may not be worked on bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant