how can theme_classic be accessed in rpy2 from ggplot2?

强颜欢笑 提交于 2019-12-11 20:01:18

问题


How can theme_classic be accessed from rpy2 in Python? I.e. this:

http://www.inside-r.org/packages/cran/ggplot2/docs/theme_classic

Is there a way to use it from rpy2?


回答1:


Yes there is. If using the manual mapping in rpy2.robjects.lib.ggplot2, is it currently missing from there, but a way to patch this should be:

import rpy2.robjects.lib.ggplot2 as ggplot2

class ThemeClassic(ggplot2.Theme):
    _constructor = ggplot2.ggplot2.theme_classic
    @classmethod
    def new(cls):
        res = cls(cls._constructor())
        return res

# Monkey patching ggplot2
ggplot2.theme_classic = ThemeClassic.new


来源:https://stackoverflow.com/questions/18540397/how-can-theme-classic-be-accessed-in-rpy2-from-ggplot2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!