How can I change the default theme in ggplot2?

前端 未结 2 1804
南旧
南旧 2021-01-18 00:02

Background

I would like to change the theme that ggplot uses, but I am having difficulty understanding the theme_update() documentation and examples.

相关标签:
2条回答
  • 2021-01-18 00:56

    I don't know why this works, but it does. Just insert the line theme_set(newtheme) before you call align.plots.

    0 讨论(0)
  • 2021-01-18 00:59

    It could be considered a bug in ggExtra::align.plots(). This function computes the size of different elements of a ggplot, such as y-axis label and legend, and aligns the plots accordingly to have the plot panels on top of each other. If you set your theme to use theme_blank() for some of those graphical elements, the function gets confused as the underlying grob (ggplot2:::.zeroGrob) isn't quite like other grobs.

    While it might be fixable (*), I think you'd be better off considering other options:

    • use a dummy facetting variable to have ggplot2 automatically align the two panels

    • use gridExtra::grid.arrange() or plain grid viewports to have the two plots on top of each other; since you removed the elements that may offset the plot positions, there should be no problem.

    (*): now fixed, try

       source("http://ggextra.googlecode.com/svn/trunk/R/align.r")
    
    0 讨论(0)
提交回复
热议问题