Skip to content

Restore names of guides after setup_panel_guides() #5064

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

Merged
merged 5 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
(@teunbrand based on @clauswilke's suggestion, #5053).
* The `lwd` alias now correctly replaced by `linewidth` instead of `size`
(@teunbrand based on @clauswilke's suggestion #5051).

* Fixed a regression in `Coord$train_panel_guides()` where names of guides were
dropped (@maxsutton, #5063)

# ggplot2 3.4.0
This is a minor release focusing on tightening up the internals and ironing out
some inconsistencies in the API. The biggest change is the addition of the
Expand Down
4 changes: 3 additions & 1 deletion R/coord-.r
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,11 @@ Coord <- ggproto("Coord",

train_panel_guides = function(self, panel_params, layers, default_mapping, params = list()) {
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))

names(aesthetics) <- aesthetics

panel_params$guides <- lapply(aesthetics, function(aesthetic) {
axis <- substr(aesthetic, 1, 1)
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-coord-.r
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,19 @@ test_that("message when replacing non-default coordinate system", {
)

})

test_that("guide names are not removed by `train_panel_guides()`", {
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
expect_equal(names(layout$panel_params[[1]]$guides),
c("x", "y", "x.sec", "y.sec"))
})