When I try to apply a custom theme using ggplot2 , it gets an error, for example:
Error in FUN("text"[[1L]], ...) : Theme element 'text' has NULL property: family, face, size, hjust, vjust, angle, lineheight
I think I should skip something basic here (my first attempt at 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:
x <- rnorm (10)
theme_set (theme_new ())
qplot (x)
Get the above error!
But:
theme_set (theme_bw ())
qplot (x)
Works great!
I am assuming that theme_update, described in https://stackoverflow.com/a/3/4203/... , does not match changing the default theme using theme_set (). If we look at a new topic in this vignette ( http://docs.ggplot2.org/dev/vignettes/themes.html ), I understand that you just need to specify all the parameters for the theme and use complete=TRUE to say this; OR use the %+replace% operator to add something to an old theme, such as theme_bw (). It didn’t work, though!
r ggplot2 themes
user3375672
source share