Rpy2,使用scale_y_continuous(标签=百分比)

时间:2015-03-07 01:23:50

标签: python rpy2

我无法弄清楚如何在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())

1 个答案:

答案 0 :(得分:-1)

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

scales = importr('scales')
scales.percent