【问题标题】:Faceted barplots rpy/ggplot2 - cannot make it work, only get one多面条形图 rpy/ggplot2 - 无法使其工作,只能获得一个
【发布时间】:2014-08-03 18:31:26
【问题描述】:

这个问题是关于 rpy2 中的 ggplot2,但我会接受 R 中的答案,如果这对你来说更容易的话。之后我会很乐意翻译解决方案。

我有一个如下所示的 rpy2 数据框(完整文件 here):

    times_seen nb_timepoints main_island other_timepoint

1            0             2           0               0
2          346             2           0               3
3          572             2           0               6
4          210             2           0               9
5          182             2           0              12
6          186             2           0              18
7          212             2           0              21
8          346             2           3               0
...

对于每个main_islandnb_timepoints,我想用它们各自的值绘制所有other_timepoints。

我有以下代码:

import rpy2.robjects.lib.ggplot2 as ggplot2
import rpy2.robjects as ro

p = ggplot2.ggplot(rpy2_df) + ggplot2.aes_string(y='times_seen', x='other_timepoint') + ggplot2.geom_bar(stat="identity")

我想得到如下图所示的东西,我该如何实现?

附言。我附加了一个文件,显示了我想要实现的大致目标(只有我想要网格、标签、轴等)

【问题讨论】:

  • 代码正常,添加分面后忘记打印了。

标签: python r ggplot2 rpy2 facet


【解决方案1】:

将以下行添加到您的情节中:

p + ggplot2.facet_grid(ro.Formula('nb_timepoints ~ main_island'))

这会产生如下图:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-24
    • 2021-07-26
    • 2022-01-23
    • 2011-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-19
    相关资源
    最近更新 更多