clauswilke/relayer

Custom aes names that contain `color` fail

Opened this issue · 0 comments

Hi Claus,
first of all, thank you for the great package :)

I just encountered a weird edge case where custom aesthetic names that contain color fail. The abbreviation col on the other hand is fine:

library(ggplot2)
library(magrittr)
library(relayer)
#> Note: The package "relayer" is highly experimental. Use at your own risk.

df1 <- data.frame(x = c(1, 2, 3))

# Custom aes called fill2 is okay
ggplot(df1, aes(x = x)) +
  geom_tile(aes(fill = x, y = 2)) +
  geom_tile(aes(fill2 = x, y = 1)) %>% rename_geom_aes(new_aes = c("fill" = "fill2")) +
  scale_colour_viridis_c(aesthetics = "fill", guide = "legend", name = "viridis A", option = "A") +
  scale_colour_viridis_c(aesthetics = "fill2", guide = "legend", name = "viridis D")
#> Warning: Ignoring unknown aesthetics: fill2

# Custom aes called col2 is okay
ggplot(df1, aes(x = x)) +
  geom_tile(aes(fill = x, y = 2)) +
  geom_tile(aes(col2 = x, y = 1)) %>% rename_geom_aes(new_aes = c("fill" = "col2")) +
  scale_colour_viridis_c(aesthetics = "fill", guide = "legend", name = "viridis A", option = "A") +
  scale_colour_viridis_c(aesthetics = "col2", guide = "legend", name = "viridis D")
#> Warning: Ignoring unknown aesthetics: col2

# Custom aes called color2 is **not** okay
ggplot(df1, aes(x = x)) +
  geom_tile(aes(fill = x, y = 2)) +
  geom_tile(aes(color2 = x, y = 1)) %>% rename_geom_aes(new_aes = c("fill" = "color2")) +
  scale_colour_viridis_c(aesthetics = "fill", guide = "legend", name = "viridis A", option = "A") +
  scale_colour_viridis_c(aesthetics = "color2", guide = "legend", name = "viridis D")
#> Warning: Ignoring unknown aesthetics: colour2
#> Error in FUN(X[[i]], ...): object 'color2' not found

Created on 2020-04-09 by the reprex package (v0.3.0)

Knowing this limitation, it is easy to circumvent, but it might be helpful for future users of the package to document this behaviour.

Best, Constantin