Cowplot让ggplot2主题消失/如何查看当前的ggplot2主题,并恢复默认?

Ale*_*lex 15 r ggplot2 cowplot

我最近安装了这个cowplot包.然而,在这样做之后,我注意到我的ggplots缺少他们的背景和网格线theme_grey()!

在此输入图像描述

创建上述每个图的代码是:

result_df %>%
    ggplot(aes_string(x = 'p', y = 'r')) +
    # theme_grey() + # uncomment this line to produce plot on right
    geom_point(aes(group = c), size = 0.5) +
    geom_line(aes(group = c), size = 0.2, linetype = 'dotted') +
    theme(axis.text.x=element_text(angle = 90, hjust = 1, vjust = 0.5)) +
    facet_grid(b ~ e, scales = "free_y") +
    scale_x_continuous(breaks = seq(0, 10, 2))
Run Code Online (Sandbox Code Playgroud)

没有明确调用+ theme_grey(),我得到左边的情节.

这里发生了什么?我以为那theme_grey()是默认的.如何查看我的默认主题是什么?

这是我的一个片段sessionInfo():

R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] ggthemes_3.3.0    cowplot_0.7.0     RPostgreSQL_0.4-1 DBI_0.5-1         knitr_1.15.1      dirmult_0.1.3-4   dplyr_0.5.0      
 [8] purrr_0.2.2       readr_1.0.0       tidyr_0.6.0       tibble_1.2        ggplot2_2.2.0     tidyverse_1.0.0  

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.8      magrittr_1.5     munsell_0.4.3    colorspace_1.3-1 R6_2.2.0         stringr_1.1.0    plyr_1.8.4       tools_3.3.2     
 [9] grid_3.3.2       gtable_0.2.0     lazyeval_0.2.0   assertthat_0.1   crayon_1.3.2     reshape2_1.4.2   rsconnect_0.6    testthat_1.0.2  
[17] labeling_0.3     stringi_1.1.2    scales_0.4.1    
Run Code Online (Sandbox Code Playgroud)

Axe*_*man 22

注意:这将不再是即将发布的版本中的问题cowplot,其中默认主题未更改.


您可以使用theme_get()查看当前的"默认"主题.

您可以使用theme_set()更改"默认"主题.

主题设置不会结转会话.

通常,您的默认值是theme_grey,但cowplot认为有必要将其更改为theme_cowplot.我真的希望它没有.

您可以使用::表示法来完全避免这种情况,也可以将包加载为:

library(cowplot)
theme_set(theme_grey())
Run Code Online (Sandbox Code Playgroud)

  • 我听到了,我实际上正在考虑将所有plot_grid和ggdraw代码分离到一个不会触及主题的单独包中.cowplot最初是关于主题的,并且它已经演变为从那以后做了越来越多的事情. (3认同)
  • 实际上,最近我遇到了越来越多的案例,我希望自己的主题没有改变.就像,我正在展示一些东西,但我已经加载了牛皮画,所以情节看起来与预期不同.将所有绘图代码移动到单独的包中是正确的方法.通过这种方式,cowplot不会改变行为,人们可以在他们不想要主题时简单地开始加载其他包.一天. (3认同)