Marcin
Marcin

Reputation: 8044

R - how to add scale functio to a theme object in ggplot2?

I am trying to prepare a custom theme for ggplot in order not to copy-paste the theme all the time. I stacked on an issue that I can not add scale functions to theme object. Does anyone know how this should be solved?

 library(ggthemes)
 theme_RTCGA <- function(base_size = 11, base_family = "", ...){

    theme_pander(gm = TRUE, gM = TRUE, ...) %+replace%
        theme(panel.grid = element_line(), 
                    panel.grid.major = element_line(colour = "grey90", size = 0.2),
                    panel.grid.minor = element_line(colour = "grey98", size = 0.5),
                    legend.position = "top") + 
  scale_colour_pander() +
  scale_fill_pander()
 }

 library(ggplot2)
 # plot
 df <- data.frame(gp = factor(rep(letters[1:3], each = 10)),
                                 y = rnorm(30))
 ds <- plyr::ddply(df, "gp", plyr::summarise, mean = mean(y), sd = sd(y))
 ggplot(df, aes(x = gp, y = y)) +
    geom_point() +
    geom_point(data = ds, aes(y = mean),
                         colour = 'red', size = 3) + theme_RTCGA()
Error: Don't know how to add scale_colour_pander() to a theme object

Upvotes: 3

Views: 2811

Answers (1)

Marcin
Marcin

Reputation: 8044

According to @baptiste comment it shoul dbe

theme_RTCGA <- function(base_size = 11, base_family = "",...){
list(theme_bw(...), scale_colour_pander())
}

Upvotes: 3

Related Questions