Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 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"))
})