Cowplot 使 ggplot2 主题消失/如何查看当前的 ggplot2 主题,并恢复默认? [英] Cowplot made ggplot2 theme disappear / How to see current ggplot2 theme, and restore the default?

查看:30
本文介绍了Cowplot 使 ggplot2 主题消失/如何查看当前的 ggplot2 主题,并恢复默认?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I recently installed the cowplot package. However, after doing this I noticed that my ggplots are missing their background and grid lines of theme_grey()!

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

The code to create each of the above plots is:

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))

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

Without explicitly calling + theme_grey(), I get the plot on the left.

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

What is happening here? I thought that theme_grey() is the default. How do I see what my default theme is?

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

here is a snippet of my 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    

推荐答案

注意:这在 cowplot 的当前版本中不再是一个问题,默认主题不是改变了.原始答案如下:

Note: this is longer an issue in current releases of cowplot, where the default theme is not changed. Original answer below:

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

You can use theme_get() to see the current "default" theme.

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

You can use theme_set() to change the "default" theme.

主题设置不会延续到会话中.

Theme settings do not carry over sessions.

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

Usually, your default will be theme_grey, but cowplot feels it's necessary to change that into theme_cowplot. I really wish it didn't.

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

You can either use :: notation to completely avoid this, or you can load the package as:

library(cowplot)
theme_set(theme_grey())

这篇关于Cowplot 使 ggplot2 主题消失/如何查看当前的 ggplot2 主题,并恢复默认?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆