Question

What's the right way to turn off all grids in Rpy2 while using the theme_bw theme? I know I can turn on theme_bw as follows:

ggplot2.theme_set(ggplot2.theme_bw(12))

but unsure how to turn off the grids. thanks.

Was it helpful?

Solution

It is basically done the same way one would do it when using ggplot2 from R.

Here is an example that turn off the grid intersecting with the X axis. More ways to "theme" a plot can be found in documentations and tutorials for 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()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top