When I try to apply a custom made theme using ggplot2
it get an error like:
Error in FUN("text"[[1L]], ...) :
Theme element 'text' has NULL property: family, face, size, hjust, vjust, angle, lineheight
I think I must miss something basic here (my first try on creating custom themes).
The theme was created based on theme_bw()
:
theme_new <- function(base_size = 12, base_family = "Helvetica"){
theme_bw(base_size = base_size, base_family = base_family) %+replace%
theme(
line = element_line(colour="black"),
text = element_text(colour="black"),
axis.title = element_text(size = 14),
axis.text = element_text(colour="black", size=8),
strip.text = element_text(size=12),
legend.key=element_rect(colour=NA, fill =NA),
panel.grid = element_blank(),
panel.border = element_rect(fill = NA, colour = "black", size=1),
panel.background = element_rect(fill = "white", colour = "black"),
strip.background = element_rect(fill = NA)
)
}
Then try it out:
x <- rnorm(10)
theme_set(theme_new())
qplot(x)
Get the above error!
However:
theme_set(theme_bw())
qplot(x)
Works fine!
I guess that the theme_update described in this stackoverflow post is not the same as changing the default theme with theme_set().
If we look at the new theme guidelines in this the vignette (http://docs.ggplot2.org/dev/vignettes/themes.html) my understanding is that one EITHER need to specify all theme parameters and use the complete=TRUE
to tell this; OR use the %+replace%
operator to add something to an old theme, like theme_bw().
Dont get it though!