drmariod
drmariod

Reputation: 11762

saving own ggplot theme in package and document it

I have some custom changes on ggplot I do all the time, when I create graphs. I want to provide this theme in my package and I am not sure how to save and document it. It is no dataset nor a function. What is the preferred way of doing so?

my_theme <- theme_bw() + theme(plot.title=element_text(vjust=1))
ggplot(mtcars, aes(mpg,cyl)) + geom_point() + ggtitle('test') + my_theme

So I want to add my_theme to the documentation.

Upvotes: 2

Views: 780

Answers (1)

drmariod
drmariod

Reputation: 11762

I just realised by looking at theme_bw that I can do it in the same way:

my_theme <- function (base_size = 12, base_family = "") {
  theme_bw(base_size = base_size, base_family = base_family) %+replace% 
    theme(plot.title=element_text(vjust=1))
}

ggplot(mtcars, aes(mpg,cyl)) + geom_point() + ggtitle('test') + my_theme()

In this way I can just document my function...

Upvotes: 8

Related Questions