Skip to content

Commit 08832e7

Browse files
Restore names of guides after setup_panel_guides() (#5064)
* Set names of aesthetics after intersecting * Add test to ensure fix is maintained * Update NEWS.md * Update NEWS.md Co-authored-by: Hiroaki Yutani <[email protected]> Co-authored-by: Hiroaki Yutani <[email protected]>
1 parent ee4600c commit 08832e7

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
(@teunbrand based on @clauswilke's suggestion, #5053).
77
* The `lwd` alias now correctly replaced by `linewidth` instead of `size`
88
(@teunbrand based on @clauswilke's suggestion #5051).
9-
9+
* Fixed a regression in `Coord$train_panel_guides()` where names of guides were
10+
dropped (@maxsutton, #5063)
11+
1012
# ggplot2 3.4.0
1113
This is a minor release focusing on tightening up the internals and ironing out
1214
some inconsistencies in the API. The biggest change is the addition of the

R/coord-.r

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,11 @@ Coord <- ggproto("Coord",
158158

159159
train_panel_guides = function(self, panel_params, layers, default_mapping, params = list()) {
160160
aesthetics <- c("x", "y", "x.sec", "y.sec")
161-
names(aesthetics) <- aesthetics
161+
162162
# If the panel_params doesn't contain the scale, there's no guide for the aesthetic
163163
aesthetics <- intersect(aesthetics, names(panel_params$guides))
164+
165+
names(aesthetics) <- aesthetics
164166

165167
panel_params$guides <- lapply(aesthetics, function(aesthetic) {
166168
axis <- substr(aesthetic, 1, 1)

tests/testthat/test-coord-.r

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,19 @@ test_that("message when replacing non-default coordinate system", {
2424
)
2525

2626
})
27+
28+
test_that("guide names are not removed by `train_panel_guides()`", {
29+
gg <- ggplot()
30+
data <- ggplot_build(gg)
31+
32+
# Excerpt from ggplot_gtable.ggplot_built
33+
plot <- data$plot
34+
layout <- data$layout
35+
data <- data$data
36+
37+
layout$setup_panel_guides(plot$guides, plot$layers, plot$mapping)
38+
39+
# Line showing change in outcome
40+
expect_equal(names(layout$panel_params[[1]]$guides),
41+
c("x", "y", "x.sec", "y.sec"))
42+
})

0 commit comments

Comments
 (0)