2

theme_bw使用主题时关闭Rpy2中所有网格的正确方法是什么?我知道我可以打开theme_bw如下:

ggplot2.theme_set(ggplot2.theme_bw(12))

但不确定如何关闭网格。谢谢。

4

1 回答 1

3

它基本上与使用 R 中的 ggplot2 时相同的方式完成。

这是一个关闭与 X 轴相交的网格的示例。更多“主题化”情节的方法可以在 ggplot2 的文档和教程中找到。

from rpy2.robjects.lib.ggplot2 import ggplot, \
                               aes_string, \
                               geom_histogram, \
                               element_blank, \
                               theme_bw, \
                               theme
from rpy2.robjects import r

nogrid_x_theme = theme(**{'panel.grid.major.x': element_blank(),
                         'panel.grid.minor.x': element_blank()})
iris = r('iris')
p = ggplot(iris) + geom_histogram(aes_string(x = 'Sepal.Width'))
p += theme_bw() + nogrid_x_theme
p.plot()
于 2013-02-17T08:03:49.467 回答