I often use the theme_hc () theme (from the ggthemes package) in ggplot2 graphs, combined with scale_colour_pander () or scale_fill_pander (). I want to create a custom function, now called myTheme, that combines these three functions into one.
I tried the following
myTheme <- function(){ theme_hc() + scale_colour_pander() + scale_fill_pander() } data <- data.frame(x=1:2,y=3:4) ggplot(data, aes(x=x, y=y)) + geom_point() + myTheme()
But, apparently, R evaluates this first inside the function and gives an error: "Error: I donβt know how to add scale_colour_pander () to the theme object."
Then i tried
myTheme <- function(){ ggplot() + theme_hc() + scale_colour_pander() + scale_fill_pander() } data <- data.frame(x=1:2,y=3:4) ggplot(data, aes(x=x, y=y)) + geom_point() + myTheme()
Which returns: "Error: I donβt know how to add o to the plot"
Is there a way to achieve the desired effect, or should I continue to combine individual commands?
source share