【问题标题】:Rpy2, use of scale_y_continuous(labels = percent)Rpy2,使用 scale_y_continuous(labels = percent)
【发布时间】:2015-03-07 01:23:50
【问题描述】:

我不知道如何在 rpy2 中使用 ggplot2 选项 scale_y_continuous(labels = percent)

示例代码:

import rpy2.robjects.lib.ggplot2 as ggplot2
base = importr('base')

mtcars = data(datasets).fetch('mtcars')['mtcars']

gp = ggplot2.ggplot(mtcars)

pp = gp + \
     ggplot2.aes_string(x='wt', y='mpg') + \
     ggplot2.geom_point() + scale_y_continuous(labels = ggplot2.percent)

pp.plot()

这引发了:

AttributeError: 'module' object has no attribute 'percent'

解决方案

scales = importr("scales")
[..some plot code here..]
.. + ggplot2.scale_y_continuous(labels = scales.percent_format())

【问题讨论】:

    标签: python rpy2


    【解决方案1】:

    这是因为该符号不在 R 包 ggplot2 的命名空间中。

    scales = importr('scales')
    scales.percent
    

    【讨论】:

    • AttributeError: 'InstalledSTPackage' object has no attribute 'percent'
    • 因为percent 不在ggplot2 中。答案固定。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-02
    相关资源
    最近更新 更多