简体   繁体   English

自动加载ggplot2自定义主题

[英]autoload ggplot2 custom theme

I'm using R and Jupyter and would like a custom theme to be loaded automatically upon startup. 我正在使用R和Jupyter,并且希望在启动时自动加载自定义主题。 I've defined a custom theme function, and when I define it within a session it works as expected. 我已经定义了一个自定义主题功能,当我在一个会话中定义它时,它可以按预期工作。 I've tried putting the definition in my local .Rprofile, but when I restart an R kernel the theme is no longer available. 我尝试将定义放入本地.Rprofile中,但是当我重新启动R内核时,该主题不再可用。 How do I make these themes persist across sessions? 如何使这些主题在各个会话中持续存在?

For example, the theme_nothing is defined via 例如,theme_nothing是通过以下方式定义的

theme_nothing <- function(base_size = 12, base_family = "Helvetica")
{
theme_bw(base_size = base_size, base_family = base_family) %+replace%
  theme(
        rect             = element_blank(),
        line             = element_blank(),
        text             = element_blank()
       )
}e 

in a cell, and when that cell is executed I can use this theme. 在一个单元格中,当执行该单元格时,我可以使用此主题。 But if I close the session, I need to redefine the theme in order to use it. 但是,如果我关闭会话,则需要重新定义主题才能使用它。 I want it to load automatically with any new R kernel. 我希望它与任何新的R内核一起自动加载。

(I've read the theme vignette but didn't find anything on persistance.) (我已经阅读了主题插图,但在持久性方面没有发现任何东西。)

Insert theme_set at the start of your script 在脚本开始处插入theme_set

theme_set(theme_nothing())

To do this you will also have to include a path to the location the theme is stored first eg, 为此,您还必须包括一个路径,该路径将首先存储主题,例如,

source('~where/the/file/is.R)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM