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 NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* Minor code formatting issues in examples and function parameters were
fixed. (@hrbrmstr)

* Class of aesthetic mapping is preserved when adding `aes()` objects. (#1624)

# ggplot2 2.1.0

## New features
Expand Down
2 changes: 2 additions & 0 deletions R/plot-construction.r
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ add_ggplot <- function(p, object, objectname) {
p <- update_guides(p, object)
} else if (inherits(object, "uneval")) {
p$mapping <- defaults(object, p$mapping)
# defaults() doesn't copy class, so copy it.
class(p$mapping) <- class(object)

labels <- lapply(object, deparse)
names(labels) <- names(object)
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-add.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
context("Adding plot elements")

test_that("Mapping class is preserved when adding uneval objects", {
p <- ggplot(mtcars) + aes(wt, mpg)
expect_identical(class(p$mapping), "uneval")
})