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: 1 addition & 1 deletion R/aes.R
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ aes_all <- function(vars) {
# refer to the data mask
structure(
lapply(vars, function(x) new_quosure(as.name(x), emptyenv())),
class = "uneval"
class = c("unlabelled_uneval", "uneval")
)
}

Expand Down
8 changes: 7 additions & 1 deletion R/labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ 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
if (inherits(mapping, "unlabelled_uneval")) {
next
}

mapping <- strip_stage(mapping)
mapping <- strip_dots(mapping, strip_pronoun = TRUE)

exclude <- names(layer$aes_params)
mapping <- mapping[setdiff(names(mapping), exclude)]

# Acquire default labels
Expand Down
2 changes: 2 additions & 0 deletions R/layer.R
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ validate_mapping <- function(mapping, call = caller_env()) {
}

cli::cli_abort(msg, call = call)
} else {
return(mapping)
}

# For backward compatibility with pre-tidy-eval layers
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ test_that("Labels from static aesthetics are ignored (#6003)", {
expect_null(get_labs(p)$colour)
})

test_that("Labels from annotations are ignored (#6316)", {
df <- data.frame(a = 1, b = 2)
p <- ggplot(df, aes(a, b)) + annotate("point", x = 1, y = 2) + geom_point()
labs <- get_labs(p)
expect_equal(labs[c("x", "y")], list(x = "a", y = "b"))
})

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