From 27db11e278ce92bef7ec9a4c8be5ee3b3078c9e1 Mon Sep 17 00:00:00 2001 From: Carson Date: Wed, 2 Oct 2019 13:05:03 -0500 Subject: [PATCH] Ignore calculated aesthetics that match specified aesthestics After https://github.com/tidyverse/ggplot2/commit/10fa0014, it's possible for calculated aes to exist for all default_aes --- R/layers2traces.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/R/layers2traces.R b/R/layers2traces.R index 432ae2c51d..1a7dd7ef85 100644 --- a/R/layers2traces.R +++ b/R/layers2traces.R @@ -10,12 +10,14 @@ layers2traces <- function(data, prestats_data, layout, p) { position = ggtype(y, "position") ) + # add on plot-level mappings, if they're inherited + map <- c(y$mapping, if (isTRUE(y$inherit.aes)) p$mapping) + # consider "calculated" aesthetics (e.g., density, count, etc) calc_aes <- y$stat$default_aes[ggfun("is_calculated_aes")(y$stat$default_aes)] - map <- c(y$mapping, calc_aes) + calc_aes <- calc_aes[!names(calc_aes) %in% names(map)] - # add on plot-level mappings, if they're inherited - if (isTRUE(y$inherit.aes)) map <- c(map, p$mapping) + map <- c(calc_aes, map) # turn symbol (e.g., ..count..) & call (e.g. calc(count)) mappings into text labels map <- ggfun("make_labels")(map)