【问题标题】:How to get a normalized fractional count in ggplot2 via rpy2 in Python?如何通过 Python 中的 rpy2 在 ggplot2 中获得归一化的小数?
【发布时间】:2013-07-03 15:24:25
【问题描述】:

我想在 rpy2(使用 ggplot2)中制作一个密度图,其中 y 值表示分数,这样 y 轴可以解释为具有特定值的“数据点的分数”。我的代码是:

df = pandas.melt(pandas.DataFrame({"x": np.random.rand(1000),
                                   "y": list(np.random.rand(20)) + [np.nan] * 980}))
# pandas dataframe to R
r_df = make_r_df(df)
r.pdf("plot.pdf")
p = ggplot2.ggplot(r_df) + \
    ggplot2.geom_density(aes_string(x="value",
                                    y="..count../..sum..(..count..)")) + \
    ggplot2.facet_wrap(Formula("~ variable"))
p.plot()

xy 有更多的点,结果图显示y 的密度一致较低——如果 y 轴归一化为点数,这没有意义。似乎 y=..count../..sum..(..count..) 没有被解释。我怎样才能让它工作?谢谢。

【问题讨论】:

    标签: python r plot ggplot2 rpy2


    【解决方案1】:

    我认为应该是sum(),而不是..sum..()(快速搜索以验证指向a similar question on SO

    【讨论】:

      猜你喜欢
      • 2011-11-23
      • 1970-01-01
      • 2018-07-17
      • 2013-02-03
      • 1970-01-01
      • 2014-03-01
      • 1970-01-01
      • 2020-08-07
      • 2016-05-11
      相关资源
      最近更新 更多