指定"stratum"和"alluvium"参数而不附加ggalluvial

Los*_*tIT 4 r ggplot2

我用ggalluvialggplot2,不过,我希望能够产生相同的情节不附加ggalluvial,但仅规定它的使用ggalluvial::.如果没有附加,我会收到以下错误:Error: Can't find stat called "stratum".

d <- data.frame(

    status = rep(c("state1","state2","state3"), rep(90, times=3)),
    cellIndex = rep(seq_len(90), times=3),
    cellCategory = c(rep(letters[seq_len(3)], each=30),
                     rep(letters[c(2,3,1)], each=30), 
                     rep(letters[c(3,1,2)], each=30))
)


ggplot2::ggplot(data=d, ggplot2::aes(x=status, stratum=cellCategory, alluvium=cellIndex,
                fill=cellCategory, label=cellCategory)) +

    ggalluvial::geom_flow(stat="alluvium", lode.guidance="rightleft", color="darkgray") +

    ggalluvial::geom_stratum() +

    ggplot2::geom_text(stat="stratum", size=3)
Run Code Online (Sandbox Code Playgroud)

Jes*_*dle 6

这是一个艰难的问题 - 挖掘ggplot2代码,stat参数粘贴你给出的字符串,然后在你所处的环境中查找该对象(在本例中为"StatStratum").因为你没有想要加载包,它将无法找到它(并且无法更改参数本身).

回答

所以你需要从ggalluvial包中保存该对象,如下所示:

StatStratum <- ggalluvial::StatStratum
Run Code Online (Sandbox Code Playgroud)

然后保留其余代码.