Skip to content

Coord::train_panel_guides() drops the names of guides #5063

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

Closed
maxsutton opened this issue Nov 28, 2022 · 0 comments · Fixed by #5064
Closed

Coord::train_panel_guides() drops the names of guides #5063

maxsutton opened this issue Nov 28, 2022 · 0 comments · Fixed by #5064

Comments

@maxsutton
Copy link
Contributor

Guides are no longer named after Coord::train_panel_guides() is executed. This occurs in Layout::setup_panel_guides() which constructs the guides if they are missing and names them via Coord::setup_panel_guides().

The issue appears to be the addition of a line of code within Coord::train_panel_guides() with the intersect() function (copied here). intersect strips the names of the input character vector.

The names of the guides help to link them with their associated scales, and the breaking of this link breaks code in an extension package. This change also undoes the preceding line, which sets the names.

    aesthetics <- c("x", "y", "x.sec", "y.sec")
    names(aesthetics) <- aesthetics

    # If the panel_params doesn't contain the scale, there's no guide for the aesthetic
    aesthetics <- intersect(aesthetics, names(panel_params$guides))

Reprex

library(ggplot2)
gg <- ggplot()
data <- ggplot_build(gg)

# Excerpt from ggplot_gtable.ggplot_built
plot <- data$plot
layout <- data$layout
data <- data$data

layout$setup_panel_guides(plot$guides, plot$layers, plot$mapping)

# Line showing change in outcome
names(layout$panel_params[[1]]$guides)

Expected output (and output prior to #3972 / commit 10eba36):

[1] "x"     "y"     "x.sec" "y.sec"

Current output:

NULL
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

Successfully merging a pull request may close this issue.

1 participant