【发布时间】: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())
【问题讨论】: