I am trying to write a function that would allow me to control both the scale_colour and scale_fill within the same call. However, when I am trying to add the two together in the same function I get this error message: Error: Cannot add ggproto objects together. Did you forget to add this object to a ggplot object?
Is there a way to overcome this?
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 3.6.3
dual_scale <- function(){
scale_color_brewer(palette="Dark2")+
scale_fill_brewer(palette="Dark2")
}
ggplot()+
dual_scale()
#> Error: Cannot add ggproto objects together. Did you forget to add this object to a ggplot object?
Created on 2021-03-25 by the reprex package (v1.0.0)

