【问题标题】:Add barplots to circles in inner nodes in partykit plotted trees将条形图添加到partykit 绘制树的内部节点中的圆圈
【发布时间】:2017-05-08 11:48:42
【问题描述】:

partykit 包在树的终端节点处绘制条形图,直观地呈现因变量类的后验概率。

我想在标准圆形/椭圆下方的内部节点中添加这些条形图。这需要使用一个混合了node_inner()node_barplot() 的函数到plot() 方法的inner_panel 参数。

但是这些函数有相当复杂的内部结构,我不知道如何混合这两者才能使内部图垂直堆叠。

有什么想法吗?

【问题讨论】:

  • 喜欢这个?ct <- ctree(factor(cyl) ~ ., data = mtcars, minsplit = 2); plot(ct, inner_panel = node_barplot(ct))
  • 不,如果你只是取消 node_barplot,这就是它所绘制的。我试图将 node_inner 和 node_barplot 合二为一。

标签: r plot party


【解决方案1】:

有可能,只是看起来不太吸引人。如果要显示拆分变量的名称和 p 值,最好调整 node_barplotmainlab 参数。在回答 Ctree classification with weights - results displayed 说明了如何在标题中包含权重 - 以类似的方式,您可以显示拆分变量和 p 值。

如果你确定要设置一个新的具有两个子面板的面板功能,你需要一点grid 编程(plot() 方法所基于的图形系统)。您需要设置一个grid.layout,然后通过生成的viewports。

make_inner_and_barplot <- function(object, ...) {
  function(node) {  
    ## layout
    pushViewport(viewport(layout = grid.layout(nrow = 2, ncol = 1,
      heights = unit(c(0.2, 0.8), "npc"))))
    ## background color
    grid.rect(gp = gpar(fill = "white", col = 0))
    ## circle
    pushViewport(viewport(layout.pos.col = 1, layout.pos.row = 1))
    node_inner(object)(node)
    popViewport()
    ## circle
    pushViewport(viewport(layout.pos.col = 1, layout.pos.row = 2))
    node_barplot(object, id = FALSE, ...)(node)
    popViewport(2)
  }
}

使用生成的面板功能,您可以执行以下操作:

ct <- ctree(factor(cyl) ~ ., data = mtcars, minsplit = 2)
plot(ct, inner_panel = make_inner_and_barplot(ct), tnex = 0.8)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-22
    • 2012-12-27
    • 1970-01-01
    • 1970-01-01
    • 2019-01-17
    • 1970-01-01
    • 1970-01-01
    • 2013-06-07
    相关资源
    最近更新 更多