Copying and modifying a default theme

前端 未结 4 1359
你的背包
你的背包 2020-12-13 13:51

I would like to create a new theme for ggplot that is based on theme_bw().

I imagine the following steps are necessary (in pseudocode):

4条回答
  •  情书的邮戳
    2020-12-13 14:05

    For the newer versions, based on the article here

    txt <- element_text(size = 14, colour = "black", face = "plain")
    bold_txt <- element_text(size = 14, colour = "black", face = "bold")
    
    theme_whatever <- function(base_size = 14, base_family = "Palatino")
    {
      theme_bw(base_size = base_size, base_family = base_family) +
      theme(
        legend.key = element_blank(), 
        strip.background = element_blank(), 
    
        text = txt, 
        plot.title = txt, 
    
        axis.title = txt, 
        axis.text = txt, 
    
        legend.title = bold_txt, 
        legend.text = txt ) 
    }
    

    Note that I use txt and txt_bold to avoid writing same stuff over and over again.

提交回复
热议问题