@@ -59,6 +59,7 @@ layer <- function(geom = NULL, stat = NULL,
5959 if (! is.null(mapping )) {
6060 mapping <- validate_mapping(mapping , call_env )
6161 }
62+ mapped_aes <- mapped_aesthetics(mapping )
6263
6364 data <- fortify(data )
6465
@@ -70,13 +71,14 @@ layer <- function(geom = NULL, stat = NULL,
7071 params $ na.rm <- params $ na.rm %|| % FALSE
7172
7273 # Split up params between aesthetics, geom, and stat
74+ all_aes <- unique(c(geom $ aesthetics(), position $ aesthetics(), stat $ aesthetics()))
7375 params <- rename_aes(params )
74- aes_params <- params [intersect(names(params ), union( geom $ aesthetics(), position $ aesthetics()) )]
76+ aes_params <- params [intersect(names(params ), all_aes )]
7577 geom_params <- params [intersect(names(params ), geom $ parameters(TRUE ))]
7678 stat_params <- params [intersect(names(params ), stat $ parameters(TRUE ))]
7779
7880 ignore <- c(" key_glyph" , " name" , " layout" )
79- all <- c(geom $ parameters(TRUE ), stat $ parameters(TRUE ), geom $ aesthetics(), position $ aesthetics() , ignore )
81+ all <- c(geom $ parameters(TRUE ), stat $ parameters(TRUE ), all_aes , ignore )
8082
8183 # Take care of plain patterns provided as aesthetic
8284 pattern <- vapply(aes_params , is_pattern , logical (1 ))
@@ -87,21 +89,31 @@ layer <- function(geom = NULL, stat = NULL,
8789 # Warn about extra params and aesthetics
8890 extra_param <- setdiff(names(params ), all )
8991 # Take care of size->linewidth renaming in layer params
90- if (geom $ rename_size && " size" %in% extra_param && ! " linewidth" %in% mapped_aesthetics( mapping ) ) {
92+ if (geom $ rename_size && " size" %in% extra_param && ! " linewidth" %in% mapped_aes ) {
9193 aes_params <- c(aes_params , params [" size" ])
9294 extra_param <- setdiff(extra_param , " size" )
9395 deprecate(" 3.4.0" , I(" Using `size` aesthetic for lines" ), I(" `linewidth`" ), user_env = user_env )
9496 }
95- if (check.param && length(extra_param ) > 0 ) {
96- cli :: cli_warn(" Ignoring unknown parameters: {.arg {extra_param}}" , call = call_env )
97+ if (check.param ) {
98+ if (length(extra_param ) > 0 ) {
99+ cli :: cli_warn(" Ignoring unknown parameters: {.arg {extra_param}}" , call = call_env )
100+ }
101+ double_defined <- intersect(mapped_aes , names(aes_params ))
102+ if (length(double_defined ) > 0 ) {
103+ cli :: cli_warn(
104+ c(
105+ " The {.and {.field {double_defined}}} aesthetic{?s} {?is/are} \\
106+ defined twice: once in {.arg mapping} and once as a static aesthetic." ,
107+ " i" = " The static aesthetic overrules the mapped aesthetic."
108+ ),
109+ call = call_env
110+ )
111+ }
97112 }
98113
99- extra_aes <- setdiff(
100- mapped_aesthetics(mapping ),
101- c(geom $ aesthetics(), stat $ aesthetics(), position $ aesthetics())
102- )
114+ extra_aes <- setdiff(mapped_aes , all_aes )
103115 # Take care of size->linewidth aes renaming
104- if (geom $ rename_size && " size" %in% extra_aes && ! " linewidth" %in% mapped_aesthetics( mapping ) ) {
116+ if (geom $ rename_size && " size" %in% extra_aes && ! " linewidth" %in% mapped_aes ) {
105117 extra_aes <- setdiff(extra_aes , " size" )
106118 deprecate(" 3.4.0" , I(" Using `size` aesthetic for lines" ), I(" `linewidth`" ), user_env = user_env )
107119 }
0 commit comments