Skip to content
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
2 changes: 2 additions & 0 deletions R/labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ setup_plot_labels <- function(plot, layers, data) {
# Find labels from every layer
for (i in seq_along(layers)) {
layer <- layers[[i]]
exclude <- names(layer$aes_params)
mapping <- layer$computed_mapping
mapping <- strip_stage(mapping)
mapping <- strip_dots(mapping, strip_pronoun = TRUE)
mapping <- mapping[setdiff(names(mapping), exclude)]

# Acquire default labels
mapping_default <- make_labels(mapping)
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ test_that("Labels can be extracted from attributes", {
expect_equal(labels$y, "disp")
})

test_that("Labels from static aesthetics are ignored (#6003)", {

df <- data.frame(x = 1, y = 1, f = 1)

p <- ggplot(df, aes(x, y, colour = f)) + geom_point()
labels <- ggplot_build(p)$plot$labels

expect_equal(labels$colour, "f")

p <- ggplot(df, aes(x, y, colour = f)) + geom_point(colour = "blue")
labels <- ggplot_build(p)$plot$labels

expect_null(labels$colour)
})

test_that("alt text is returned", {
p <- ggplot(mtcars, aes(mpg, disp)) +
geom_point()
Expand Down